From 2e53a15bda512e42ff978f02cd209fe2b69c5ce2 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Wed, 25 Feb 2015 15:06:18 +0530 Subject: [PATCH] Fieldname validation, fixes frappe/erpnext#2608 --- frappe/__init__.py | 7 ++++--- .../doctype/custom_field/custom_field.json | 3 ++- frappe/desk/notifications.py | 17 ++++++++++++----- frappe/model/db_schema.py | 8 ++++---- 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/frappe/__init__.py b/frappe/__init__.py index aa9085f8ba..cb2586b728 100644 --- a/frappe/__init__.py +++ b/frappe/__init__.py @@ -202,21 +202,22 @@ def msgprint(msg, small=0, raise_exception=0, as_table=False): :param raise_exception: [optional] Raise given exception and show message. :param as_table: [optional] If `msg` is a list of lists, render as HTML table. """ + from utils import cstr, encode + def _raise_exception(): if raise_exception: if flags.rollback_on_exception: db.rollback() import inspect if inspect.isclass(raise_exception) and issubclass(raise_exception, Exception): - raise raise_exception, msg + raise raise_exception, encode(msg) else: - raise ValidationError, msg + raise ValidationError, encode(msg) if flags.mute_messages: _raise_exception() return - from utils import cstr if as_table and type(msg) in (list, tuple): msg = '' + ''.join([''+''.join(['' % c for c in r])+'' for r in msg]) + '
%s
' diff --git a/frappe/custom/doctype/custom_field/custom_field.json b/frappe/custom/doctype/custom_field/custom_field.json index 9a6bf8e69f..1fcba035b6 100644 --- a/frappe/custom/doctype/custom_field/custom_field.json +++ b/frappe/custom/doctype/custom_field/custom_field.json @@ -50,6 +50,7 @@ "search_index": 0 }, { + "default": "Data", "fieldname": "fieldtype", "fieldtype": "Select", "in_filter": 1, @@ -275,7 +276,7 @@ ], "icon": "icon-glass", "idx": 1, - "modified": "2015-02-05 05:11:36.425019", + "modified": "2015-02-25 03:39:23.573928", "modified_by": "Administrator", "module": "Custom", "name": "Custom Field", diff --git a/frappe/desk/notifications.py b/frappe/desk/notifications.py index c8841d55a8..99db13f790 100644 --- a/frappe/desk/notifications.py +++ b/frappe/desk/notifications.py @@ -26,13 +26,20 @@ def get_notifications(): if d in notification_count: open_count_doctype[d] = notification_count[d] else: - result = frappe.get_list(d, fields=["count(*)"], - filters=condition, as_list=True)[0][0] + try: + result = frappe.get_list(d, fields=["count(*)"], + filters=condition, as_list=True)[0][0] - open_count_doctype[d] = result + except Exception, e: + # OperationalError: (1412, 'Table definition has changed, please retry transaction') + if e.args[0]!=1412: + raise - cache.set_value("notification_count:" + frappe.session.user + ":" + d, - result) + else: + open_count_doctype[d] = result + + cache.set_value("notification_count:" + frappe.session.user + ":" + d, + result) for m in config.for_module: if m in notification_count: diff --git a/frappe/model/db_schema.py b/frappe/model/db_schema.py index 253fbb3450..1ec7eb2727 100644 --- a/frappe/model/db_schema.py +++ b/frappe/model/db_schema.py @@ -402,12 +402,12 @@ class DbManager: def validate_column_name(n): n = n.replace(' ','_').strip().lower() - if re.search("[\W]", n, re.UNICODE): - frappe.throw(_("Fieldname {0} cannot contain letters, numbers or spaces").format(n), InvalidColumnName) + special_characters = re.findall("[\W]", n, re.UNICODE) + if special_characters: + special_characters = ", ".join('"{0}"'.format(c) for c in special_characters) + frappe.throw(_("Fieldname {0} cannot have special characters like {1}").format(cstr(n), special_characters), InvalidColumnName) return n - - def remove_all_foreign_keys(): frappe.db.sql("set foreign_key_checks = 0") frappe.db.commit()