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
- 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
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}")
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