Revert "fix(query): unique aliasing for linked field joins"

This commit is contained in:
Aarol D'Souza 2026-05-01 18:15:23 +05:30 committed by GitHub
parent b011532a7e
commit 8b47c6e5a0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 7 additions and 12 deletions

View file

@ -2087,6 +2087,7 @@ class LinkTableField(DynamicTableField):
def _get_joined_table(self):
table = frappe.qb.DocType(self.doctype)
if self.doctype == self.parent_doctype:
table = table.as_(f"tab{self.doctype}_{self.link_fieldname}")
return table

View file

@ -1238,14 +1238,8 @@ class TestDBQuery(IntegrationTestCase):
fields=fields,
).get_sql()
self.assertIn(
self.normalize_sql("LEFT JOIN `tabSelf Linked DocType` `tabSelf Linked DocType_parent_ref`"),
self.normalize_sql(query),
)
self.assertIn(
self.normalize_sql("LEFT JOIN `tabSelf Linked DocType` `tabSelf Linked DocType_sibling_ref`"),
self.normalize_sql(query),
)
self.assertIn("LEFT JOIN `tabSelf Linked DocType` `tabSelf Linked DocType_parent_ref`", query)
self.assertIn("LEFT JOIN `tabSelf Linked DocType` `tabSelf Linked DocType_sibling_ref`", query)
def test_select_star_expansion(self):
count = frappe.get_list("Language", [{"SUM": 1}, {"COUNT": "*"}], as_list=1, order_by=None)[0]

View file

@ -371,10 +371,10 @@ class TestQuery(IntegrationTestCase):
fields=["name"],
filters={"module.app_name": "frappe"},
).get_sql(),
"SELECT `tabDocType`.`name` FROM `tabDocType` LEFT JOIN `tabModule Def` `tabModule Def_module` ON `tabModule Def_module`.`name`=`tabDocType`.`module` WHERE `tabModule Def_module`.`app_name`='frappe'",
"SELECT `tabDocType`.`name` FROM `tabDocType` LEFT JOIN `tabModule Def` ON `tabModule Def`.`name`=`tabDocType`.`module` WHERE `tabModule Def`.`app_name`='frappe'",
)
query = "SELECT `tabDocType`.`name` FROM `tabDocType` LEFT JOIN `tabModule Def` `tabModule Def_module` ON `tabModule Def_module`.`name`=`tabDocType`.`module` WHERE `tabModule Def_module`.`app_name` LIKE 'frap%'"
query = "SELECT `tabDocType`.`name` FROM `tabDocType` LEFT JOIN `tabModule Def` ON `tabModule Def`.`name`=`tabDocType`.`module` WHERE `tabModule Def`.`app_name` LIKE 'frap%'"
query = query.replace("LIKE", "ILIKE" if frappe.db.db_type == "postgres" else "LIKE")
self.assertQueryEqual(
frappe.qb.get_query(
@ -756,7 +756,7 @@ class TestQuery(IntegrationTestCase):
"DocType",
fields=["name", "module.app_name as app_name"],
).get_sql(),
"SELECT `tabDocType`.`name`,`tabModule Def_module`.`app_name` `app_name` FROM `tabDocType` LEFT JOIN `tabModule Def` `tabModule Def_module` ON `tabModule Def_module`.`name`=`tabDocType`.`module`",
"SELECT `tabDocType`.`name`,`tabModule Def`.`app_name` `app_name` FROM `tabDocType` LEFT JOIN `tabModule Def` ON `tabModule Def`.`name`=`tabDocType`.`module`",
)
# fields now has strict validation, so this test is not valid anymore