fix: check if doctype exists before replacing null values (#8507)

* fix: check if doctype exists before replacing null values

Signed-off-by: Chinmay D. Pai <chinmaydpai@gmail.com>

* fix: use re.sub instead of replace

Signed-off-by: Chinmay D. Pai <chinmaydpai@gmail.com>
This commit is contained in:
Chinmay Pai 2019-09-27 14:35:46 +05:30 committed by GitHub
parent 0e6de280aa
commit ed34713b51
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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):
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))))