Skip to content

Conversation

@kmagusiak
Copy link
Contributor

@kmagusiak kmagusiak commented Jun 19, 2024

Add the new module in util.

odoo/odoo#170009

@robodoo
Copy link
Contributor

robodoo commented Jun 19, 2024

Pull request status dashboard

@KangOl
Copy link
Contributor

KangOl commented Jun 24, 2024

Please refer to the odoo/enterprise/design-themes PR (if applicable) in the commit message.
It's needed by UpgradeCI to correctly build this PR with the corresponding branches.

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.

@KangOl
Copy link
Contributor

KangOl commented Jun 24, 2024

upgradeci retry with always only product

@kmagusiak kmagusiak force-pushed the master-odoo-domains-krma branch from 5d922c4 to 75995f8 Compare June 26, 2024 20:48
@kmagusiak kmagusiak force-pushed the master-odoo-domains-krma branch from 75995f8 to d04730f Compare July 5, 2024 10:24
@kmagusiak kmagusiak force-pushed the master-odoo-domains-krma branch 3 times, most recently from c1f14fd to cc14aca Compare July 12, 2024 05:47
@kmagusiak kmagusiak force-pushed the master-odoo-domains-krma branch from cc14aca to 5fc5007 Compare July 18, 2024 15:27
@kmagusiak kmagusiak force-pushed the master-odoo-domains-krma branch 4 times, most recently from 35f332a to ecb02d4 Compare July 19, 2024 06:21
@kmagusiak kmagusiak marked this pull request as ready for review July 19, 2024 06:53
@kmagusiak kmagusiak force-pushed the master-odoo-domains-krma branch from ecb02d4 to 9a28b72 Compare July 23, 2024 14:04
@kmagusiak kmagusiak force-pushed the master-odoo-domains-krma branch 2 times, most recently from 67d7263 to a5e4a37 Compare August 4, 2024 06:09
@kmagusiak kmagusiak force-pushed the master-odoo-domains-krma branch from a5e4a37 to 72636dd Compare August 19, 2024 15:45
@kmagusiak kmagusiak force-pushed the master-odoo-domains-krma branch from 72636dd to 9bfd854 Compare September 9, 2024 09:51
@kmagusiak kmagusiak force-pushed the master-odoo-domains-krma branch from 9bfd854 to 0871208 Compare September 16, 2024 10:46
@KangOl
Copy link
Contributor

KangOl commented Sep 16, 2024

upgradeci retry with always only helpdesk

@kmagusiak kmagusiak force-pushed the master-odoo-domains-krma branch from 0871208 to 1bd88a5 Compare September 23, 2024 15:57
@kmagusiak kmagusiak force-pushed the master-odoo-domains-krma branch from 1bd88a5 to 5fa525c Compare October 7, 2024 16:08
@kmagusiak kmagusiak force-pushed the master-odoo-domains-krma branch from 5fa525c to 310a0c8 Compare October 23, 2024 09:08
@kmagusiak kmagusiak force-pushed the master-odoo-domains-krma branch 3 times, most recently from b623c1e to ea0f06f Compare November 19, 2024 08:13
@kmagusiak kmagusiak force-pushed the master-odoo-domains-krma branch from ea0f06f to aef38f5 Compare November 26, 2024 13:28
@kmagusiak kmagusiak force-pushed the master-odoo-domains-krma branch 2 times, most recently from a3c8fdc to 2878002 Compare December 12, 2024 12:55
@kmagusiak kmagusiak requested a review from KangOl December 16, 2024 14:40
@kmagusiak
Copy link
Contributor Author

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
@kmagusiak kmagusiak force-pushed the master-odoo-domains-krma branch from 2878002 to 87d1ece Compare December 16, 2024 14:45
# the Domain factory normalized but also distributes operators during creation of domains

def normalize_domain(domain):
"""Return a normalized version of the domain.
Copy link
Contributor

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.

Copy link
Contributor Author

@kmagusiak kmagusiak Dec 16, 2024

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.

Copy link
Contributor

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...

Copy link
Contributor

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 ;)

Copy link
Contributor Author

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

Copy link
Contributor

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):
Copy link
Contributor

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']))

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Member

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".

Copy link
Contributor

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),))
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Member

Choose a reason for hiding this comment

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

Well spotted.

@kmagusiak kmagusiak requested a review from aj-fuentes December 16, 2024 15:34
Copy link
Contributor

@aj-fuentes aj-fuentes left a 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+

@kmagusiak
Copy link
Contributor Author

@robodoo r+

@robodoo
Copy link
Contributor

robodoo commented Dec 16, 2024

@kmagusiak linked pull request(s) odoo/documentation#10214 not ready. Linked PRs are not staged until all of them are ready.

robodoo pushed a commit to odoo/odoo that referenced this pull request Dec 17, 2024
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>
robodoo pushed a commit to odoo/documentation that referenced this pull request Dec 17, 2024
odoo/odoo#170009

closes #10214

Related: odoo/enterprise#65013
Related: odoo/upgrade-util#99
Signed-off-by: Antoine Vandevenne (anv) <anv@odoo.com>
@robodoo robodoo closed this in 93e50b2 Dec 17, 2024
@robodoo robodoo added the 18.1 label Dec 17, 2024
@kmagusiak kmagusiak deleted the master-odoo-domains-krma branch December 17, 2024 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants