From cc498d3d54408efa9a318fc8d8ac01f9fa4886c5 Mon Sep 17 00:00:00 2001 From: Sagar Vora <16315650+sagarvora@users.noreply.github.com> Date: Fri, 16 Jan 2026 21:52:45 +0530 Subject: [PATCH] fix: dont mutate filters for custom queries --- frappe/desk/search.py | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/frappe/desk/search.py b/frappe/desk/search.py index d18ce76748..71483ff13c 100644 --- a/frappe/desk/search.py +++ b/frappe/desk/search.py @@ -109,28 +109,10 @@ def search_widget( if filters is None: filters = {} - are_filters_dict = isinstance(filters, dict) - include_disabled = False - if not query and are_filters_dict: - if "include_disabled" in filters: - if filters["include_disabled"] == 1: - include_disabled = True - filters.pop("include_disabled") - - filters = [make_filter_tuple(doctype, key, value) for key, value in filters.items()] - are_filters_dict = False - if for_link_validation: - if are_filters_dict: - # we add filter if possible, otherwise rely on txt - if "name" not in filters: - filters["name"] = txt - else: - filters.append([doctype, "name", "=", txt]) - as_dict = False - # for custom queries that don't respect filters but respect limit (rare) - # or for when we have to rely on txt + # for custom queries, we don't mutate filters + # we have to rely on txt # we want to match "A" with "A" only and not "A1", "BA" etc. page_length = PAGE_LENGTH_FOR_LINK_VALIDATION @@ -163,6 +145,19 @@ def search_widget( return [] meta = frappe.get_meta(doctype) + + include_disabled = False + if isinstance(filters, dict): + if "include_disabled" in filters: + if filters["include_disabled"] == 1: + include_disabled = True + filters.pop("include_disabled") + + filters = [make_filter_tuple(doctype, key, value) for key, value in filters.items()] + + if for_link_validation: + filters.append([doctype, "name", "=", txt]) + or_filters = [] # build from doctype