From 7f34d510f2ce5ee69cce2c4eabe4306d0118b54b Mon Sep 17 00:00:00 2001 From: gavin Date: Tue, 31 Jan 2023 14:43:26 +0530 Subject: [PATCH] fix(db_query): Allow link field to have 'tab' (#19820) * fix(db_query): Allow link field to have 'tab' Issue: Occurence of tab was used to check if the selected field is a table name and not a fieldname. This caused DocTypes with fields like `tablets` or `table_name` to break List Views. Change: Check if the field exists in meta to be sure that the selectable is a field. * fix: Split once to ensure at most 2 args --- frappe/model/db_query.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/frappe/model/db_query.py b/frappe/model/db_query.py index 36bd325e26..a5a4039223 100644 --- a/frappe/model/db_query.py +++ b/frappe/model/db_query.py @@ -317,13 +317,16 @@ class DatabaseQuery: # convert child_table.fieldname to `tabChild DocType`.`fieldname` for field in self.fields: - if "." in field and "tab" not in field: + if "." in field: original_field = field alias = None if " as " in field: - field, alias = field.split(" as ") - linked_fieldname, fieldname = field.split(".") + field, alias = field.split(" as ", 1) + linked_fieldname, fieldname = field.split(".", 1) linked_field = frappe.get_meta(self.doctype).get_field(linked_fieldname) + # this is not a link field + if not linked_field: + continue linked_doctype = linked_field.options if linked_field.fieldtype == "Link": self.append_link_table(linked_doctype, linked_fieldname)