From 3fd60b70eeec03b29d426407a3202d111bef7658 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Wed, 18 Aug 2021 11:42:44 +0530 Subject: [PATCH 1/4] fix: Length change for docfield not updated in Database --- frappe/custom/doctype/customize_form/customize_form.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/frappe/custom/doctype/customize_form/customize_form.py b/frappe/custom/doctype/customize_form/customize_form.py index 8de194fb00..94f25a41aa 100644 --- a/frappe/custom/doctype/customize_form/customize_form.py +++ b/frappe/custom/doctype/customize_form/customize_form.py @@ -193,6 +193,16 @@ class CustomizeForm(Document): if prop == "fieldtype": self.validate_fieldtype_change(df, meta_df[0].get(prop), df.get(prop)) + elif prop == "length": + old_value_length = cint(meta_df[0].get(prop)) + new_value_length = cint(df.get(prop)) + + if new_value_length and (old_value_length > new_value_length): + self.check_length_for_fieldtypes.append({'df': df, 'old_value': meta_df[0].get(prop)}) + self.validate_fieldtype_length() + else: + self.flags.update_db = True + elif prop == "allow_on_submit" and df.get(prop): if not frappe.db.get_value("DocField", {"parent": self.doc_type, "fieldname": df.fieldname}, "allow_on_submit"): From cd9b07b3bbdb80c27370301f9f786c537a9ff646 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Sat, 21 Aug 2021 19:07:44 +0530 Subject: [PATCH 2/4] test: Add test case for docfield length property update --- .../doctype/customize_form/test_customize_form.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/frappe/custom/doctype/customize_form/test_customize_form.py b/frappe/custom/doctype/customize_form/test_customize_form.py index aef95cd676..6783e52d68 100644 --- a/frappe/custom/doctype/customize_form/test_customize_form.py +++ b/frappe/custom/doctype/customize_form/test_customize_form.py @@ -188,6 +188,19 @@ class TestCustomizeForm(unittest.TestCase): def test_core_doctype_customization(self): self.assertRaises(frappe.ValidationError, self.get_customize_form, 'User') + def test_save_customization_length_field_property(self): + # Using Notification Log doctype as it doesn't have any other custom fields + d = self.get_customize_form("Notification Log") + + document_name = d.get("fields", {"fieldname": "document_name"})[0] + document_name.length = 255 + d.run_method("save_customization") + + self.assertEqual(frappe.db.get_value("Property Setter", + {"doc_type": "Notification Log", "property": "length", "field_name": "document_name"}, "value"), '255') + + self.assertTrue(d.flags.update_db) + def test_custom_link(self): try: # create a dummy doctype linked to Event From 783165c01e4bd0433814bd145a4960b92130100b Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Mon, 30 Aug 2021 12:00:31 +0530 Subject: [PATCH 3/4] fix: Retry get_redis_conn until "sure" If ConnectionError or BusyLoadingError occurs, try every second for up-to 10 times. Why: `bench start` exits just as i run it at times. This happens when the worker's processes each try to fetch a redis conn but redis isnt up yet. The 3 workeer processes exit with 1 and our procman gives up too. --- frappe/utils/background_jobs.py | 9 ++++++++- requirements.txt | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/frappe/utils/background_jobs.py b/frappe/utils/background_jobs.py index 567268f760..b8f3372540 100755 --- a/frappe/utils/background_jobs.py +++ b/frappe/utils/background_jobs.py @@ -3,12 +3,14 @@ import socket import time from uuid import uuid4 from collections import defaultdict +from typing import List import redis -from typing import List +from redis.exceptions import BusyLoadingError, ConnectionError from rq import Connection, Queue, Worker from rq.logutils import setup_loghandlers +from tenacity import retry, retry_if_exception_type, stop_after_attempt, wait_fixed import frappe from frappe import _ @@ -233,6 +235,11 @@ def validate_queue(queue, default_queue_list=None): if queue not in default_queue_list: frappe.throw(_("Queue should be one of {0}").format(', '.join(default_queue_list))) +@retry( + retry=retry_if_exception_type(BusyLoadingError) | retry_if_exception_type(ConnectionError), + stop=stop_after_attempt(10), + wait=wait_fixed(1) +) def get_redis_conn(username=None, password=None): if not hasattr(frappe.local, 'conf'): raise Exception('You need to call frappe.init') diff --git a/requirements.txt b/requirements.txt index 51327953d5..be96520a02 100644 --- a/requirements.txt +++ b/requirements.txt @@ -77,3 +77,4 @@ Whoosh~=2.7.4 wrapt~=1.12.1 xlrd~=2.0.1 zxcvbn-python~=4.4.24 +tenacity~=8.0.1 From cd17ca274ca3684fa53450415ff2d2292dbcdb61 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Tue, 31 Aug 2021 10:44:11 +0530 Subject: [PATCH 4/4] fix: Check column length from information schema --- .../custom/doctype/customize_form/test_customize_form.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/frappe/custom/doctype/customize_form/test_customize_form.py b/frappe/custom/doctype/customize_form/test_customize_form.py index 6783e52d68..266ece8a1e 100644 --- a/frappe/custom/doctype/customize_form/test_customize_form.py +++ b/frappe/custom/doctype/customize_form/test_customize_form.py @@ -201,6 +201,13 @@ class TestCustomizeForm(unittest.TestCase): self.assertTrue(d.flags.update_db) + length = frappe.db.sql("""SELECT character_maximum_length + FROM information_schema.columns + WHERE table_name = 'tabNotification Log' + AND column_name = 'document_name'""")[0][0] + + self.assertEqual(length, 255) + def test_custom_link(self): try: # create a dummy doctype linked to Event