diff --git a/py/webnotes/model/db_schema.py b/py/webnotes/model/db_schema.py index 1c18ae1fe5..c7e9aa2a69 100644 --- a/py/webnotes/model/db_schema.py +++ b/py/webnotes/model/db_schema.py @@ -295,7 +295,7 @@ class DbManager: """ Just returns the output of Desc tables. """ - return list(self.conn.sql("DESC %s"%table)) + return list(self.conn.sql("DESC `%s`"%table)) def get_tables_list(self,target=None): diff --git a/py/webnotes/widgets/doclistview.py b/py/webnotes/widgets/doclistview.py index 556504e776..9da59fb36e 100644 --- a/py/webnotes/widgets/doclistview.py +++ b/py/webnotes/widgets/doclistview.py @@ -38,6 +38,11 @@ def get(arg=None): fields = json.loads(data['fields']) tables = ['`tab' + data['doctype'] + '`'] + + # select fields if they exist in table + columns = [".".join([tables[0], col]) for col in get_table_columns(data['doctype'])] + fields = [f for f in fields if f in columns] + docstatus = json.loads(data['docstatus']) if docstatus: conditions = [tables[0] + '.docstatus in (' + ','.join(docstatus) + ')'] @@ -98,10 +103,11 @@ def get_stats(): import json tags = json.loads(webnotes.form_dict.get('stats')) doctype = webnotes.form_dict['doctype'] - stats = {} + columns = get_table_columns(doctype) for tag in tags: + if not tag in columns: continue tagcount = webnotes.conn.sql("""select %(tag)s, count(*) from `tab%(doctype)s` where ifnull(%(tag)s, '')!='' @@ -132,7 +138,7 @@ def scrub_user_tags(tagcount): rlist.append([tag, rdict[tag]]) return rlist - - - +def get_table_columns(table): + res = webnotes.conn.sql("DESC `tab%s`" % table, as_dict=1) + if res: return [r['Field'] for r in res]