fix(spp_cel_domain): handle relational fields and SQL JOINs in CEL#41
fix(spp_cel_domain): handle relational fields and SQL JOINs in CEL#41
Conversation
Summary of ChangesHello @jeremi, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the Common Expression Language (CEL) domain functionality by improving its ability to handle relational fields and generate accurate SQL queries. It allows 'one2many' and 'many2many' fields to be used intuitively as bare predicates, simplifying complex expressions. The changes also ensure that SQL queries involving related fields are correctly constructed with necessary JOINs, preventing data retrieval issues. Furthermore, the cache invalidation mechanism for CEL variables has been made more robust, guaranteeing that changes to variables are immediately reflected across all CEL components. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces important fixes and features, including correctly handling SQL generation for domains with related fields using query.select() in cel_executor.py and cel_sql_builder.py, enabling the use of relational fields (one2many, many2many) as bare predicates in CEL expressions via cel_translator.py, and enhancing cache invalidation in cel_variable.py. A security audit confirmed no vulnerabilities, highlighting the use of Odoo's SQL objects and SQL.identifier to prevent SQL injection, and robust security measures in the CEL parser against sandbox escape or denial-of-service attacks. The new tests are comprehensive, though one could be made more specific.
| found = False | ||
| for leaf in domain: | ||
| if isinstance(leaf, tuple) and leaf[0] == "program_membership_ids" and leaf[1] == "!=": | ||
| found = True | ||
| break | ||
| self.assertTrue(found, f"Expected '!= False' domain for one2many, got: {domain}") |
There was a problem hiding this comment.
The current test assertion is a bit weak as it only checks for the presence of the != operator but not the full domain leaf ('program_membership_ids', '!=', False). This could lead to a false positive if the generated domain was, for example, ('program_membership_ids', '!=', True).
To make the test more robust and specific, I suggest checking for the exact expected tuple within the domain. This can be done more concisely using any().
expected_leaf = ("program_membership_ids", "!=", False)
# The domain can be complex due to base_domains, so we check if any leaf matches.
found = any(leaf == expected_leaf for leaf in domain if isinstance(leaf, tuple))
self.assertTrue(found, f"Expected '{expected_leaf}' to be in domain, but got: {domain}")
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## 19.0 #41 +/- ##
==========================================
- Coverage 71.31% 69.00% -2.32%
==========================================
Files 299 404 +105
Lines 23618 37746 +14128
==========================================
+ Hits 16844 26047 +9203
- Misses 6774 11699 +4925
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
- Handle one2many/many2many fields as bare CEL predicates - Use query.select() for SQL with JOINs instead of raw field access - Add tests for relational predicate handling
Replace weak operator-only check with an exact tuple match to prevent false positives from incorrect values (e.g. True instead of False).
dbf4c17 to
3b5c0ce
Compare
Summary
query.select()for SQL with JOINs instead of raw field access, fixing incorrect query generationOrigin
Cherry-picked from
openspp-modules-v2branchclaude/global-alliance-policy-basket.Test plan
Note
Medium Risk
Touches core query translation/execution paths (SQL generation and predicate compilation), which could change result sets or performance for existing expressions; mitigated by added regression tests.
Overview
Fixes CEL compilation and SQL fast-path generation for relational lookups.
Domains converted to SQL now use
query.select()(in bothCelExecutor._domain_to_id_sqlandSQLBuilder.select_ids_from_domain) so the generated subquery includes requiredFROM/JOINclauses for related-field domains (e.g.gender_id.uri) and still applies record rules even for empty domains.CEL translation now treats bare
one2many/many2manyfields as truthy predicates by compiling them to[(field, '!=', False)], and variable CRUD now invalidates all CEL caches viaspp.cel.service.invalidate_caches(); adds targeted tests covering relational predicates and cache invalidation behavior.Written by Cursor Bugbot for commit dbf4c17. This will update automatically on new commits. Configure here.