Explorar el Código

fix: coalesce `not in` queries (#18099) (#18101)

* fix: get workspaces with empty module fields

* Revert "fix: get workspaces with empty module fields"

This reverts commit 1f194be2c3.

* fix: always coalesce `not in` queries

Co-authored-by: Ankush Menat <ankush@frappe.io>
(cherry picked from commit 235171796d)

Co-authored-by: Shariq Ansari <30859809+shariquerik@users.noreply.github.com>
version-14
mergify[bot] hace 2 años
committed by GitHub
padre
commit
4012d32be6
No se encontró ninguna clave conocida en la base de datos para esta firma ID de clave GPG: 4AEE18F83AFDEB23
Se han modificado 2 ficheros con 8 adiciones y 1 borrados
  1. +4
    -1
      frappe/model/db_query.py
  2. +4
    -0
      frappe/tests/test_db_query.py

+ 4
- 1
frappe/model/db_query.py Ver fichero

@@ -613,7 +613,10 @@ class DatabaseQuery:


elif f.operator.lower() in ("in", "not in"): elif f.operator.lower() in ("in", "not in"):
# if values contain '' or falsy values then only coalesce column # if values contain '' or falsy values then only coalesce column
can_be_null = not f.value or any(v is None or v == "" for v in f.value)
# for `in` query this is only required if values contain '' or values are empty.
# for `not in` queries we can't be sure as column values might contain null.
if f.operator.lower() == "in":
can_be_null = not f.value or any(v is None or v == "" for v in f.value)


values = f.value or "" values = f.value or ""
if isinstance(values, str): if isinstance(values, str):


+ 4
- 0
frappe/tests/test_db_query.py Ver fichero

@@ -749,6 +749,10 @@ class TestReportview(FrappeTestCase):
self.assertNotIn("ifnull", frappe.get_all("User", {"name": ("in", ["a", "b"])}, run=0)) self.assertNotIn("ifnull", frappe.get_all("User", {"name": ("in", ["a", "b"])}, run=0))
self.assertIn("ifnull", frappe.get_all("User", {"name": ("in", ["a", None])}, run=0)) self.assertIn("ifnull", frappe.get_all("User", {"name": ("in", ["a", None])}, run=0))
self.assertIn("ifnull", frappe.get_all("User", {"name": ("in", ["a", ""])}, run=0)) self.assertIn("ifnull", frappe.get_all("User", {"name": ("in", ["a", ""])}, run=0))
self.assertIn("ifnull", frappe.get_all("User", {"name": ("in", [])}, run=0))
self.assertIn("ifnull", frappe.get_all("User", {"name": ("not in", ["a"])}, run=0))
self.assertIn("ifnull", frappe.get_all("User", {"name": ("not in", [])}, run=0))
self.assertIn("ifnull", frappe.get_all("User", {"name": ("not in", [""])}, run=0))




def add_child_table_to_blog_post(): def add_child_table_to_blog_post():


Cargando…
Cancelar
Guardar