From 8e5f1a56d337d095fc77b858a45c09e22c6212f5 Mon Sep 17 00:00:00 2001 From: Sumit Jain Date: Tue, 3 Feb 2026 12:47:01 +0530 Subject: [PATCH] test: Update assertions for IN/NOT IN with empty lists Refined test cases to ensure that empty lists in IN and NOT IN operators return the correct SQL conditions (1=0 and 1=1 respectively) and do not include IFNULL. This enhances the accuracy of the query handling in the database tests. --- frappe/tests/test_db_query.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/frappe/tests/test_db_query.py b/frappe/tests/test_db_query.py index 5110671578..07150ce80b 100644 --- a/frappe/tests/test_db_query.py +++ b/frappe/tests/test_db_query.py @@ -1050,15 +1050,21 @@ class TestDBQuery(IntegrationTestCase): self.assertNotIn("IF", frappe.get_all("User", {"first_name": ("in", ["a", "b"])}, run=0).get_sql()) self.assertIn("IFNULL", frappe.get_all("User", {"first_name": ("in", ["a", None])}, run=0).get_sql()) self.assertIn("IFNULL", frappe.get_all("User", {"first_name": ("in", ["a", ""])}, run=0).get_sql()) - self.assertIn("IFNULL", frappe.get_all("User", {"first_name": ("in", [])}, run=0).get_sql()) + # Empty list with IN should return 1=0, not use IFNULL + self.assertIn("1=0", frappe.get_all("User", {"first_name": ("in", [])}, run=0).get_sql()) + self.assertNotIn("IFNULL", frappe.get_all("User", {"first_name": ("in", [])}, run=0).get_sql()) self.assertIn("IFNULL", frappe.get_all("User", {"first_name": ("not in", ["a"])}, run=0).get_sql()) - self.assertIn("IFNULL", frappe.get_all("User", {"first_name": ("not in", [])}, run=0).get_sql()) + # Empty list with NOT IN should return 1=1, not use IFNULL + self.assertIn("1=1", frappe.get_all("User", {"first_name": ("not in", [])}, run=0).get_sql()) + self.assertNotIn("IFNULL", frappe.get_all("User", {"first_name": ("not in", [])}, run=0).get_sql()) self.assertIn("IFNULL", frappe.get_all("User", {"first_name": ("not in", [""])}, run=0).get_sql()) # primary key is never nullable self.assertNotIn("IFNULL", frappe.get_all("User", {"name": ("in", ["a", None])}, run=0).get_sql()) self.assertNotIn("IFNULL", frappe.get_all("User", {"name": ("in", ["a", ""])}, run=0).get_sql()) self.assertNotIn("IFNULL", frappe.get_all("User", {"name": ("in", (""))}, run=0).get_sql()) + # Empty tuple with IN should return 1=0, not use IFNULL + self.assertIn("1=0", frappe.get_all("User", {"name": ("in", ())}, run=0).get_sql()) self.assertNotIn("IFNULL", frappe.get_all("User", {"name": ("in", ())}, run=0).get_sql()) def test_coalesce_with_datetime_ops(self):