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.
This commit is contained in:
Sumit Jain 2026-02-03 12:47:01 +05:30
parent c6868b11c6
commit 8e5f1a56d3

View file

@ -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):