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
This commit is contained in:
gavin 2023-01-31 14:43:26 +05:30 committed by GitHub
parent b3b846472e
commit 7f34d510f2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

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