From 96f27650207659597a730aa654f75f3273e7ed35 Mon Sep 17 00:00:00 2001 From: IamSaiyyamChhetri Date: Tue, 22 Oct 2024 16:02:12 +0530 Subject: [PATCH] fix: Change in condition builder --- frappe/model/db_query.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/frappe/model/db_query.py b/frappe/model/db_query.py index c36ebf592d86..552ba5191c04 100644 --- a/frappe/model/db_query.py +++ b/frappe/model/db_query.py @@ -840,16 +840,20 @@ def prepare_filter_condition(self, f): elif f.operator.lower() == "is": if f.value == "set": - f.operator = "!=" + f.operator = "IS NOT NULL" if frappe.conf.db_type == "postgres" else "!=" # Value can technically be null, but comparing with null will always be falsy # Not using coalesce here is faster because indexes can be used. # null != '' -> null ~ falsy # '' != '' -> false can_be_null = False - elif f.value == "not set": - f.operator = "=" - fallback = "''" - can_be_null = True + elif f.value == "not set": + if frappe.conf.db_type == "postgres": + f.operator = "IS NULL" + can_be_null = False + else: + f.operator = "=" + fallback = "''" + can_be_null = True value = "" @@ -897,7 +901,7 @@ def prepare_filter_condition(self, f): value = f"{tname}.{quote}{f.value.name}{quote}" # escape value - elif escape and isinstance(value, str): + elif escape and isinstance(value, str) and frappe.conf.db_type != "postgres": value = f"{frappe.db.escape(value, percent=False)}" if (