From 9a774de21ed863b44f849aa3307c31222142d56b Mon Sep 17 00:00:00 2001 From: Sagar Vora <16315650+sagarvora@users.noreply.github.com> Date: Mon, 5 Jan 2026 19:02:04 +0530 Subject: [PATCH] fix: add permission conditions to where clause instead of join --- frappe/database/query.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/frappe/database/query.py b/frappe/database/query.py index f327e3f385..2f2fa5f749 100644 --- a/frappe/database/query.py +++ b/frappe/database/query.py @@ -1833,13 +1833,11 @@ class LinkTableField(DynamicTableField): table = frappe.qb.DocType(self.doctype) main_table = frappe.qb.DocType(self.parent_doctype) if not query.is_joined(table): - clause = table.name == getattr(main_table, self.link_fieldname) - + query = query.left_join(table).on(table.name == getattr(main_table, self.link_fieldname)) if engine and engine.apply_permissions: if condition := engine.get_permission_conditions(self.doctype, table): - clause &= condition + query = query.where(condition) - query = query.left_join(table).on(clause) return query