diff --git a/spp_cel_domain/README.rst b/spp_cel_domain/README.rst index 9a72fa2b4..8ad8d603b 100644 --- a/spp_cel_domain/README.rst +++ b/spp_cel_domain/README.rst @@ -142,6 +142,13 @@ Dependencies Changelog ========= +19.0.2.1.1 +~~~~~~~~~~ + +- fix(executor): include households with no matching memberships for + ``count >= 0`` in SQL and when zero satisfies a Python count + comparison without a base domain + 19.0.2.1.0 ~~~~~~~~~~ diff --git a/spp_cel_domain/__manifest__.py b/spp_cel_domain/__manifest__.py index 550c3d0f3..d53b3c3a2 100644 --- a/spp_cel_domain/__manifest__.py +++ b/spp_cel_domain/__manifest__.py @@ -2,7 +2,7 @@ { "name": "CEL Domain Query Builder", "summary": "Write simple CEL-like expressions to filter records (OpenSPP/OpenG2P friendly)", - "version": "19.0.2.1.0", + "version": "19.0.2.1.1", "license": "LGPL-3", "development_status": "Production/Stable", "author": "OpenSPP.org, OpenSPP Community", diff --git a/spp_cel_domain/models/cel_executor.py b/spp_cel_domain/models/cel_executor.py index b9fb36003..45931026a 100644 --- a/spp_cel_domain/models/cel_executor.py +++ b/spp_cel_domain/models/cel_executor.py @@ -156,10 +156,9 @@ def _count_to_sql(self, p: CountThrough) -> SQL | None: Returns SQL selecting parent IDs where child count matches the comparison. Special handling for edge cases: - - count == 0: Parents with NO matching children (NOT IN subquery) - - count < N or count <= N: Fall back to Python (needs special handling for 0-count parents) - - count != N: Fall back to Python (complex edge cases) - - count > 0, count >= N, count > N: Use GROUP BY + HAVING (standard approach) + - count >= 0: Select all parents, including those with no matching children. + - count == 0, count < N, count <= N, count != N: Fall back to Python. + - Other supported comparisons: Use GROUP BY + HAVING. """ try: through_table = self.env[p.through_model]._table @@ -197,6 +196,12 @@ def _count_to_sql(self, p: CountThrough) -> SQL | None: op = "=" rhs = p.rhs + # Every count is at least zero. + # GROUP BY on memberships alone would omit parents with no matching rows. + if op == ">=" and isinstance(rhs, (int, float)) and not isinstance(rhs, bool) and rhs == 0: + parent_model = self.env[p.through_model]._fields[p.parent_field].comodel_name + return builder.select_ids_from_domain(parent_model, []) + # Fall back to Python for comparisons that need zero-count parents included # These are complex to handle correctly in SQL without the parent table: # - count == 0: Parents with no rows in membership table won't appear in SQL @@ -856,7 +861,7 @@ def _exec_count(self, p: CountThrough) -> list[int]: # noqa: C901 base_domain = cfg.get("base_domain") candidate_parents: set[int] = set() - if parent_model_name and base_domain: + if parent_model_name and (base_domain or self._compare(0, p.op, p.rhs)): candidate_parents = set(int(pid) for pid in self.env[parent_model_name].search(base_domain).ids) if child_subplan is not None: diff --git a/spp_cel_domain/readme/HISTORY.md b/spp_cel_domain/readme/HISTORY.md index 1b4fd10d3..0971d7602 100644 --- a/spp_cel_domain/readme/HISTORY.md +++ b/spp_cel_domain/readme/HISTORY.md @@ -1,3 +1,7 @@ +### 19.0.2.1.1 + +- fix(executor): include households with no matching memberships for `count >= 0` in SQL and when zero satisfies a Python count comparison without a base domain + ### 19.0.2.1.0 - feat(sql): compile CEL ternary expressions to SQL CASE via `to_sql_case`, with `case_when`/`comparison` builders and a right-associative ternary parsing fix diff --git a/spp_cel_domain/static/description/index.html b/spp_cel_domain/static/description/index.html index f280ce2a1..9644c39f8 100644 --- a/spp_cel_domain/static/description/index.html +++ b/spp_cel_domain/static/description/index.html @@ -522,6 +522,14 @@

Changelog

+

19.0.2.1.1

+ +
+

19.0.2.1.0

-
+

19.0.2.0.0