From ddcdabbf6de766359a7fd52c6a7900dda937fc73 Mon Sep 17 00:00:00 2001 From: "Chinmay D. Pai" Date: Fri, 27 Sep 2019 12:55:50 +0530 Subject: [PATCH 1/2] fix: check if doctype exists before replacing null values Signed-off-by: Chinmay D. Pai --- frappe/patches/v12_0/replace_null_values_in_tables.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frappe/patches/v12_0/replace_null_values_in_tables.py b/frappe/patches/v12_0/replace_null_values_in_tables.py index e2895ed6f7..a2971cf384 100644 --- a/frappe/patches/v12_0/replace_null_values_in_tables.py +++ b/frappe/patches/v12_0/replace_null_values_in_tables.py @@ -14,7 +14,7 @@ def execute(): update_column_table_map[field.TABLE_NAME].append("`{fieldname}`=COALESCE(`{fieldname}`, 0)".format(fieldname=field.COLUMN_NAME)) for table in frappe.db.get_tables(): - if update_column_table_map.get(table): + if update_column_table_map.get(table) and frappe.db.exists("DocType", table.replace("tab", "")): frappe.db.sql("""UPDATE `{table}` SET {columns}""" .format(table=table, columns=", ".join(update_column_table_map.get(table)))) From 99ecd01cd1d224a5fc8fe6253a77518d1f08e28c Mon Sep 17 00:00:00 2001 From: "Chinmay D. Pai" Date: Fri, 27 Sep 2019 13:05:40 +0530 Subject: [PATCH 2/2] fix: use re.sub instead of replace Signed-off-by: Chinmay D. Pai --- frappe/patches/v12_0/replace_null_values_in_tables.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frappe/patches/v12_0/replace_null_values_in_tables.py b/frappe/patches/v12_0/replace_null_values_in_tables.py index a2971cf384..023a255a6d 100644 --- a/frappe/patches/v12_0/replace_null_values_in_tables.py +++ b/frappe/patches/v12_0/replace_null_values_in_tables.py @@ -1,4 +1,5 @@ import frappe +import re def execute(): fields = frappe.db.sql(""" @@ -14,7 +15,7 @@ def execute(): update_column_table_map[field.TABLE_NAME].append("`{fieldname}`=COALESCE(`{fieldname}`, 0)".format(fieldname=field.COLUMN_NAME)) for table in frappe.db.get_tables(): - if update_column_table_map.get(table) and frappe.db.exists("DocType", table.replace("tab", "")): + if update_column_table_map.get(table) and frappe.db.exists("DocType", re.sub('^tab', '', table)): frappe.db.sql("""UPDATE `{table}` SET {columns}""" .format(table=table, columns=", ".join(update_column_table_map.get(table))))