-
Notifications
You must be signed in to change notification settings - Fork 81
[IMP] core: odoo.domains #99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Please refer to the odoo/enterprise/design-themes PR (if applicable) in the commit message. If you don't want to have notifications on the related PR each time you force push, simply don't force push and add new fixup commits that will be squashed before the r+. Note that UpgradeCI will also extract the info from the PR body. It is however better to have those references in the commit message itself. This message is a canned response and thus may not be totally accurate. |
|
upgradeci retry with always only product |
5d922c4 to
75995f8
Compare
75995f8 to
d04730f
Compare
c1f14fd to
cc14aca
Compare
cc14aca to
5fc5007
Compare
35f332a to
ecb02d4
Compare
ecb02d4 to
9a28b72
Compare
67d7263 to
a5e4a37
Compare
a5e4a37 to
72636dd
Compare
72636dd to
9bfd854
Compare
9bfd854 to
0871208
Compare
|
upgradeci retry with always only helpdesk |
0871208 to
1bd88a5
Compare
1bd88a5 to
5fa525c
Compare
5fa525c to
310a0c8
Compare
b623c1e to
ea0f06f
Compare
ea0f06f to
aef38f5
Compare
a3c8fdc to
2878002
Compare
|
upgradeci retry with always only product |
Adding domain management as an AST to the odoo.orm. We import the new package and fallback to expression.py, which will be deprecated in future releases. odoo/odoo#170009
2878002 to
87d1ece
Compare
| # the Domain factory normalized but also distributes operators during creation of domains | ||
|
|
||
| def normalize_domain(domain): | ||
| """Return a normalized version of the domain. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't we implement this in terms of the new Domain factory?
return list(_dom.Domain(domain)) would this be enough?
If not, I still believe it's better to use the new implementation, it will bring better compatibility for future versions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is not strictly equivalent and some tests were failing.
Here is an example from an older build: https://runbot.odoo.com/runbot/build/64886163
One of the differences is stated above: list(Domain(xxx)) is distribute_not(normalize_domain(xxx)).
I suggest that we merge as-is, I would like to avoid mixing behaviour changes in this PR. I can implement a follow-up PR with the simplification.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That failure doesn't make sense 🤯 (irrelevantly of the current implementation) it's a test that should only run when going over 17.3. Why is it trying to upgrade from 17 to master, that's not valid. Only >=18 can be upgraded to master. Checking with runbot team...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest that we merge as-is, and I can implement a follow-up PR with the simplification.
If you want to unblock it for the freeze, I'm OK. But do not forget to improve it later ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aj-fuentes Added to my TODO list
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that the last runbot run upgraded 18->master. Thus the tests that failed before, shouldn't anymore.
| return result | ||
|
|
||
| def normalize_leaf(leaf): | ||
| if not is_leaf(leaf): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we allow in the linked PR in community to register optimizations that work accross all models we could do here:
list(domains.Domain("a","<>",1)._optimize(None))
which I can only seem to get to work with
list(domains.Domain("valid_field","<>",1)._optimize(self.env['base']))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you should optimize domains during the migration, it does more than simple rewrites.
That operator is replaced automatically for a long time and continues to work for now.
Anyways, same remark as above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, we don't need to optimize leaves. Only very simple details that are cross-model. That's why I asked if there was some sort of support for that. Anyway, we can keep this mocked normalize_leaf for now, but it should be aligned with current implementation. Namely it shouldn't warn if we don't warn for the equivalent in community. I'm not sure if we should do the replacing of operators either, seeing how that may affect the actual optimizations in the new implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.env['base'] is a particular model.
You need a different sentinel value for "any possible model".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need a different sentinel value for "any possible model".
Indeed, to me it should be None. I was just hacking my way to get a feeling how this now works :)
| if operator == "<>": | ||
| operator = "!=" | ||
| if isinstance(right, bool) and operator in ("in", "not in"): | ||
| _logger.warning("The domain term '%s' should use the '=' or '!=' operator.", ((left, original, right),)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this still true?
>>> list(domains.Domain("id","in",True)._optimize(self.env['base']))
[('id', 'in', [True])]
>>> list(domains.Domain("active","in",True)._optimize(self.env['res.users']))
[('active', 'in', [True])]
>>> list(domains.Domain("active","in",False)._optimize(self.env['res.users']))
[(0, '=', 1)]The last output looks odd... I'd expect an error or [('active','in',[False])]/[('active','=',False)] as output.
If we no longer show any warning then why would we show one during the upgrade. If we now silently replace the leaf by something else, the warnings should be now more like This is translated to ... since Odoo 19.
I still think it's better to implement normalize_leaf using the new machinery at least for the cases where it doesn't do anything too involved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation is a copy of what is done today.
The last line comes from an optimization where in falsy_value results in a constant (because there are domains like ('a', '=', []) which do not mean = False, but in [] which is always False. More warnings and deprecations will come in the future on the community branch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation is a copy of what is done today.
That's what I understood. My point: we cannot keep for the future what's done today. It should be aligned. For merging the task this may be OK, but for the long term whatever we do here should be aligned with what's expected from the implementation in community.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well spotted.
aj-fuentes
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is acceptable for a first iteration. I won't block it.
@robodoo delegate+
|
@robodoo r+ |
|
@kmagusiak linked pull request(s) odoo/documentation#10214 not ready. Linked PRs are not staged until all of them are ready. |
New domains.py module to perform domain manipulation.
This will replace the `odoo.osv.expression` module. The domain is now
represented as an immutable abstract syntax tree; it is always normalized
and allows to extend it more easily for things like adding optimizations.
Today domains are manipulated as lists. This adds overhead when trying to
understand the algorithms and you need to normalize manually. You may get
undesired behaviours when you forget to normalize the domain or when you
mutate the list. Concatenating two non-normalized lists is not the same
as the and operator and if a field's search method mutates the domain
that comes from a field's domain, it mutates it for the running instance.
The newer API is fully backwards-compatible and looks like:
domain = Domain(some_domain_from_user)
domain &= Domain('id', '>', 5) # add a condition with an AND
list(domain) # get the domain in the old-format
task-3864512
closes #170009
Related: odoo/enterprise#65013
Related: odoo/documentation#10214
Related: odoo/upgrade-util#99
Signed-off-by: Raphael Collet <rco@odoo.com>
odoo/odoo#170009 closes #10214 Related: odoo/enterprise#65013 Related: odoo/upgrade-util#99 Signed-off-by: Antoine Vandevenne (anv) <anv@odoo.com>

Add the new module in util.
odoo/odoo#170009