From 766d4540b96f7d07f3cd97838afde988ba29241d Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Tue, 18 Nov 2014 15:23:49 +0530 Subject: [PATCH 1/4] [fixes] [minor] based on error reports --- .../core/doctype/custom_field/custom_field.py | 7 +++--- .../doctype/custom_field/test_custom_field.py | 23 ++++++++++++++++++- frappe/database.py | 4 +++- frappe/model/db_schema.py | 4 +++- frappe/tests/test_db.py | 5 ++++ frappe/utils/data.py | 9 +++++--- 6 files changed, 42 insertions(+), 10 deletions(-) diff --git a/frappe/core/doctype/custom_field/custom_field.py b/frappe/core/doctype/custom_field/custom_field.py index 2c2adb92bf..e848481a6d 100644 --- a/frappe/core/doctype/custom_field/custom_field.py +++ b/frappe/core/doctype/custom_field/custom_field.py @@ -9,7 +9,6 @@ from frappe import _ from frappe.model.document import Document class CustomField(Document): - def autoname(self): self.set_fieldname() self.name = self.dt + "-" + self.fieldname @@ -40,9 +39,9 @@ class CustomField(Document): self.create_property_setter() # update the schema - if not frappe.flags.in_test: - from frappe.model.db_schema import updatedb - updatedb(self.dt) + # if not frappe.flags.in_test: + from frappe.model.db_schema import updatedb + updatedb(self.dt) def on_trash(self): # delete property setter entries diff --git a/frappe/core/doctype/custom_field/test_custom_field.py b/frappe/core/doctype/custom_field/test_custom_field.py index ad4def6175..9ddacbe294 100644 --- a/frappe/core/doctype/custom_field/test_custom_field.py +++ b/frappe/core/doctype/custom_field/test_custom_field.py @@ -1,10 +1,31 @@ +# -*- coding: utf-8 -*- + # Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors # See license.txt +from __future__ import unicode_literals + import frappe import unittest test_records = frappe.get_test_records('Custom Field') +from frappe.model.db_schema import InvalidColumnName + class TestCustomField(unittest.TestCase): - pass + def test_non_ascii(self): + cf = frappe.get_doc({ + "doctype":"Custom Field", + "dt": "ToDo", + "fieldtype": "Data", + "fieldname": "δου" + }) + + self.assertRaises(InvalidColumnName, cf.insert) + + # todo = frappe.get_doc({ + # "doctype": "ToDo", + # "description": "test", + # "δου": "greek" + # }) + # todo.insert() diff --git a/frappe/database.py b/frappe/database.py index d40bf90cb8..bb3085c038 100644 --- a/frappe/database.py +++ b/frappe/database.py @@ -556,4 +556,6 @@ class Database: self._conn = None def escape(self, s): - return unicode(MySQLdb.escape_string((s or "").encode("utf-8")), "utf-8") + if isinstance(s, unicode): + s = (s or "").encode("utf-8") + return unicode(MySQLdb.escape_string(s), "utf-8") diff --git a/frappe/model/db_schema.py b/frappe/model/db_schema.py index 5c11f6f742..e4e370f4ab 100644 --- a/frappe/model/db_schema.py +++ b/frappe/model/db_schema.py @@ -13,6 +13,8 @@ import frappe from frappe import _ from frappe.utils import cstr, cint +class InvalidColumnName(frappe.ValidationError): pass + type_map = { 'Currency': ('decimal', '18,6') ,'Int': ('int', '11') @@ -373,7 +375,7 @@ def validate_column_name(n): n = n.replace(' ','_').strip().lower() import re if re.search("[\W]", n): - frappe.throw(_("Fieldname {0} cannot contain letters, numbers or spaces").format(n)) + frappe.throw(_("Fieldname {0} cannot contain letters, numbers or spaces").format(n), InvalidColumnName) return n diff --git a/frappe/tests/test_db.py b/frappe/tests/test_db.py index f7de01066e..be0e5fcca6 100644 --- a/frappe/tests/test_db.py +++ b/frappe/tests/test_db.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- + # Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors # MIT License. See license.txt @@ -14,3 +16,6 @@ class TestDB(unittest.TestCase): self.assertEquals(frappe.db.get_value("User", {"name": ["<=", "Administrator"]}), "Administrator") self.assertEquals("test1@example.com", frappe.db.get_value("User", {"name": [">", "s"]})) self.assertEquals("test1@example.com", frappe.db.get_value("User", {"name": [">=", "t"]})) + + def test_escape(self): + frappe.db.escape("香港濟生堂製藥有限公司 - IT".encode("utf-8")) diff --git a/frappe/utils/data.py b/frappe/utils/data.py index 7d69f2bef4..952c6bf900 100644 --- a/frappe/utils/data.py +++ b/frappe/utils/data.py @@ -165,9 +165,12 @@ def formatdate(string_date=None, format_string=None): out = frappe.local.user_format or "yyyy-mm-dd" - return out.replace("dd", date.strftime("%d"))\ - .replace("mm", date.strftime("%m"))\ - .replace("yyyy", date.strftime("%Y")) + try: + return out.replace("dd", date.strftime("%d"))\ + .replace("mm", date.strftime("%m"))\ + .replace("yyyy", date.strftime("%Y")) + except ValueError, e: + raise frappe.ValidationError, str(e) def global_date_format(date): """returns date as 1 January 2012""" From 53edaa23fa229fd617d04693dca5ccae49226911 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Wed, 19 Nov 2014 11:48:11 +0530 Subject: [PATCH 2/4] [fix] reportview.js, SUP10183 --- frappe/public/js/frappe/views/reportview.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frappe/public/js/frappe/views/reportview.js b/frappe/public/js/frappe/views/reportview.js index 3e34258249..a849cf1e34 100644 --- a/frappe/public/js/frappe/views/reportview.js +++ b/frappe/public/js/frappe/views/reportview.js @@ -197,7 +197,7 @@ frappe.views.ReportView = frappe.ui.Listing.extend({ // get table_name.column_name get_full_column_name: function(v) { if(!v) return; - return (v[1] ? ('`tab' + v[1] + '`') : this.tab_name) + '.' + v[0]; + return (v[1] ? ('`tab' + v[1] + '`') : this.tab_name) + '.`' + v[0] + '`'; }, // build columns for slickgrid From 9051e56d94375ec1a488e0200debbac09ba15729 Mon Sep 17 00:00:00 2001 From: Pratik Vyas Date: Wed, 19 Nov 2014 14:26:40 +0530 Subject: [PATCH 3/4] remove test for custom field --- .../doctype/custom_field/test_custom_field.py | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/frappe/core/doctype/custom_field/test_custom_field.py b/frappe/core/doctype/custom_field/test_custom_field.py index 9ddacbe294..41b0ac3a30 100644 --- a/frappe/core/doctype/custom_field/test_custom_field.py +++ b/frappe/core/doctype/custom_field/test_custom_field.py @@ -13,19 +13,4 @@ test_records = frappe.get_test_records('Custom Field') from frappe.model.db_schema import InvalidColumnName class TestCustomField(unittest.TestCase): - def test_non_ascii(self): - cf = frappe.get_doc({ - "doctype":"Custom Field", - "dt": "ToDo", - "fieldtype": "Data", - "fieldname": "δου" - }) - - self.assertRaises(InvalidColumnName, cf.insert) - - # todo = frappe.get_doc({ - # "doctype": "ToDo", - # "description": "test", - # "δου": "greek" - # }) - # todo.insert() + pass From 06e7c67c155031372a544cbebce0e71b6a70a3b4 Mon Sep 17 00:00:00 2001 From: Pratik Vyas Date: Wed, 19 Nov 2014 15:03:44 +0600 Subject: [PATCH 4/4] bumped to version 4.5.9 --- frappe/__version__.py | 2 +- frappe/hooks.py | 2 +- setup.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/frappe/__version__.py b/frappe/__version__.py index 9f9f645091..12cf0f14d4 100644 --- a/frappe/__version__.py +++ b/frappe/__version__.py @@ -1 +1 @@ -__version__ = "4.5.8" +__version__ = "4.5.9" diff --git a/frappe/hooks.py b/frappe/hooks.py index 704053f337..f632099952 100644 --- a/frappe/hooks.py +++ b/frappe/hooks.py @@ -3,7 +3,7 @@ app_title = "Frappe Framework" app_publisher = "Web Notes Technologies Pvt. Ltd." app_description = "Full Stack Web Application Framework in Python" app_icon = "assets/frappe/images/frappe.svg" -app_version = "4.5.8" +app_version = "4.5.9" app_color = "#3498db" app_email = "support@frappe.io" diff --git a/setup.py b/setup.py index 72b4637a12..c8184c1a8e 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ from setuptools import setup, find_packages import os -version = "4.5.8" +version = "4.5.9" with open("requirements.txt", "r") as f: install_requires = f.readlines()