Skip to content

Fix SQL and Python parity for CEL member counts of at least zero - #615

Merged
gonzalesedwin1123 merged 3 commits into
OpenSPP:19.0from
laxmanacharya8:fix/cel-count-zero-parity
Dec 2, 2026
Merged

gonzalesedwin1123 merged 3 commits into
OpenSPP:19.0from
laxmanacharya8:fix/cel-count-zero-parity

Conversation

@laxmanacharya8

@laxmanacharya8 laxmanacharya8 commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Why is this change needed?

members.count(m, true) >= 0 should match any household in the candidate set. The SQL fast path used GROUP BY over membership rows, which excluded households with zero matching members. The Python fallback returned them when the profile supplied a base domain.

How was the change implemented?

For count >= 0, the SQL path selects parent IDs directly and the caller still applies its base domain and record rules. With no base domain, Python now includes parents with zero matching memberships whenever zero satisfies the comparison. This covers count == 0, count < N, count <= N, and count != N where applicable. Previously, a matching membership on any parent could cause those zero-count parents to be dropped.

New tests

  • An isolated household with no members matches members.count(m, true) >= 0 through both paths.
  • Both paths include zero-count parents for count >= 0 in a profile without a base domain.
  • With no base domain, the Python fallback for members.count(m, true) == 0 includes an empty household and excludes a populated household.
  • A seeded differential test runs 96 CEL rules on 18 synthetic households and asserts which execution path ran as well as the complete set of selected households.

Tests run locally

Odoo 19 Community and PostgreSQL 16.14. The 648 existing spp_cel_domain tests passed on the original executor. The minimal regression and generated test both failed before the fix. The full suite passed with the fix (652 tests, zero failures or errors).

How to test manually

Run the Odoo shell reproduction from the issue. Both paths now return the empty household with a count of 1.

Closes #614.

@gonzalesedwin1123 gonzalesedwin1123 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the report and the fix. The bug in #614 is real, and the change is small and correct. Reviewed at 815530b.

What I checked

  • SQL path: GROUP BY ... HAVING COUNT(*) >= 0 over membership rows cannot return a parent with no rows, so the count >= 0 shortcut is the right shape. It returns parent IDs through the existing select_ids_from_domain helper, and the callers still AND the profile's base domain and run the result through an ORM search, so record rules and the active filter keep applying.
  • Python path: with the new condition, zero-count parents are considered even when no base domain is set. Note this is broader than the title: it also changes count == 0, < N, <= N and != N without a base domain, which previously dropped empty parents whenever at least one membership row matched. I think that is the correct behaviour, but please mention it in the PR description so the description matches the diff.
  • The docstring fix is right; the old text claimed a NOT IN subquery for count == 0 that the code never built.
  • Tests: the seeded generator is deterministic, the ages are well clear of the 5 and 65 boundaries, and the 96 rules / 18 households match the description. load_profile returns a deep copy, so overriding base_domain in the test does not leak into other tests.

Requested before merge

  1. Bump spp_cel_domain in __manifest__.py to 19.0.2.1.1 and add a matching ### 19.0.2.1.1 entry at the top of readme/HISTORY.md (a - fix(executor): ... bullet). Every code fix in this repo needs both. Please do not regenerate README.rst / static/description/index.html locally: the CI pre-commit job prints the exact expected diff for those, and that output is what should be committed. Heads-up that #535 also targets 2.1.1 and touches cel_executor.py; whichever merges second will renumber.

Suggested, not blocking

  1. A test for the broadened Python behaviour, for example members.count(m, true) == 0 with base_domain = [], asserting that a household with no members is returned. The generated test only uses operators that take the SQL path, so that branch is currently uncovered.
  2. type(rhs) in (int, float) could be isinstance(rhs, (int, float)) and not isinstance(rhs, bool) if excluding booleans is the intent; fine to leave as is.

CI has not run on this PR yet because workflows on fork PRs need a maintainer's approval, so I have not seen the suite pass. A maintainer will approve the run.

@codecov

codecov Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.05%. Comparing base (a71e8f0) to head (67efee7).
⚠️ Report is 5 commits behind head on 19.0.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             19.0     #615      +/-   ##
==========================================
- Coverage   77.17%   76.05%   -1.12%     
==========================================
  Files         727      759      +32     
  Lines       47006    52762    +5756     
==========================================
+ Hits        36276    40129    +3853     
- Misses      10730    12633    +1903     
Flag Coverage Δ
spp_analytics 93.25% <ø> (ø)
spp_api_v2_change_request 73.37% <ø> (ø)
spp_api_v2_cycles 71.03% <ø> (ø)
spp_api_v2_data 77.77% <ø> (ø)
spp_api_v2_entitlements 70.23% <ø> (ø)
spp_api_v2_gis 74.60% <ø> (ø)
spp_api_v2_programs 94.55% <ø> (ø)
spp_api_v2_simulation 71.19% <ø> (ø)
spp_approval 50.85% <ø> (ø)
spp_base_common 91.07% <ø> (ø)
spp_case_cel 89.50% <ø> (ø)
spp_case_entitlements 100.00% <ø> (ø)
spp_case_programs 100.00% <ø> (ø)
spp_cel_domain 63.91% <100.00%> (?)
spp_cel_event 85.34% <ø> (?)
spp_cel_load_testing 98.11% <ø> (ø)
spp_programs 67.58% <ø> (ø)
spp_registry 89.00% <ø> (ø)
spp_security 69.56% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
spp_cel_domain/models/cel_executor.py 63.87% <100.00%> (ø)

... and 31 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@gonzalesedwin1123

Copy link
Copy Markdown
Member

Thanks for the quick turnaround. All three review points are addressed, and the new == 0 test covers the branch I was worried about.

One note on the extra commit on your branch: I pushed 67efee7, which regenerates spp_cel_domain/README.rst and static/description/index.html. Those two files are generated from the fragments in readme/ (including HISTORY.md) by a pre-commit hook, so any HISTORY change makes them stale and the pre-commit job fails until they are updated. My earlier instruction on this was not clear enough, so I applied the fix myself rather than send you on another round trip.

For future PRs: don't regenerate them locally, because local tool versions render slightly differently from CI. Push the fragment change, let the pre-commit job fail, and commit exactly the diff it prints at the end of its log.

CI is green on 67efee7. Please pull before pushing anything else to this branch.

@gonzalesedwin1123 gonzalesedwin1123 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed at 67efee7. All requested changes are in: version bump to 19.0.2.1.1 with a matching HISTORY entry, a test for the == 0 Python path without a base domain, and the isinstance check. CI is green. Thanks for the fix.

@gonzalesedwin1123
gonzalesedwin1123 merged commit 5d21858 into OpenSPP:19.0 Dec 2, 2026
35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CEL SQL fast path excludes empty households from member count >= 0

2 participants