Skip to content
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

[IMP] Move SUPERUSER_ID to odoo.api #182371

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

kmagusiak
Copy link
Contributor

@kmagusiak kmagusiak commented Oct 1, 2024

Description of the issue/feature this PR addresses:
Move odoo.SUPERUSER_ID to odoo.api.SUPERUSER_ID.
In order to become a namespace package, odoo package should not contain any variables, only modules.

odoo/enterprise#71223
odoo/upgrade#6585
odoo/upgrade-util#144
task-4069446


I confirm I have signed the CLA and read the PR guidelines at www.odoo.com/submit-pr

@robodoo
Copy link
Contributor

robodoo commented Oct 1, 2024

Pull request status dashboard

@kmagusiak kmagusiak changed the title Master init superuser krma Move SUPERUSER_ID to odoo.api Oct 1, 2024
@C3POdoo C3POdoo added the RD research & development, internal work label Oct 1, 2024
@kmagusiak kmagusiak force-pushed the master-init-superuser-krma branch from ac0fdd1 to b1c05ce Compare October 1, 2024 14:45
kmagusiak added a commit to odoo-dev/upgrade-util that referenced this pull request Oct 1, 2024
@kmagusiak kmagusiak marked this pull request as ready for review October 1, 2024 17:00
@C3POdoo C3POdoo requested review from a team, UemuS, hupo-odoo, rco-odoo, ryv-odoo and aab-odoo and removed request for a team October 1, 2024 17:02
@C3POdoo C3POdoo requested review from davidmonnom and removed request for a team October 22, 2024 10:24
@kmagusiak kmagusiak force-pushed the master-init-superuser-krma branch from 7b68103 to 0665b4b Compare October 22, 2024 10:36
@kmagusiak kmagusiak requested a review from Julien00859 October 22, 2024 12:48
@kmagusiak
Copy link
Contributor Author

PR is rebased and ready.

@odoo/rd-security The security warning in __getattr__ of the init file. The goal is to load and show a warning when using variables directly defined in odoo module. The module and name are whitelisted at the beginning of the function in the match statement.

kmagusiak added a commit to odoo-dev/upgrade-util that referenced this pull request Oct 25, 2024
@kmagusiak kmagusiak force-pushed the master-init-superuser-krma branch from 0665b4b to 01fd2f1 Compare October 25, 2024 11:53
Copy link
Member

@Julien00859 Julien00859 left a comment

Choose a reason for hiding this comment

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

The day we make odoo a pure package, we'll no longer be able to import odoo and then use odoo.something unless odoo.something is imported. It means that one day odoo.api.SUPERUSER_ID is going to break unless import odoo.api.

We can decide to postpone the problem to later, we'll have MANY files to update in the future anyway.

addons/product_email_template/models/account_move.py Outdated Show resolved Hide resolved
addons/hr_recruitment/models/hr_job.py Show resolved Hide resolved
addons/product_expiry/__init__.py Outdated Show resolved Hide resolved
addons/purchase_stock/models/stock_rule.py Show resolved Hide resolved
addons/repair/__init__.py Outdated Show resolved Hide resolved
odoo/orm/registry.py Outdated Show resolved Hide resolved
odoo/service/db.py Show resolved Hide resolved
odoo/tests/common.py Outdated Show resolved Hide resolved
odoo/tests/test_module_operations.py Outdated Show resolved Hide resolved
odoo/tools/cloc.py Outdated Show resolved Hide resolved
@kmagusiak kmagusiak force-pushed the master-init-superuser-krma branch 3 times, most recently from 3a447c9 to 7f5c07b Compare October 25, 2024 15:22
@kmagusiak
Copy link
Contributor Author

The day we make odoo a pure package, we'll no longer be able to import odoo and then use odoo.something unless odoo.something is imported. It means that one day odoo.api.SUPERUSER_ID is going to break unless import odoo.api.

We can decide to postpone the problem to later, we'll have MANY files to update in the future anyway.

I have made changes according to your comments.

If the module is loaded it won't fail. So if you do this in an addon, odoo.api will be imported before the execution of the module.
I started a PR in which I'm no longer importing a lot of modules during import odoo and fixes such bare imports: #185330.

@kmagusiak kmagusiak requested a review from Julien00859 October 25, 2024 15:24
Copy link
Member

@rco-odoo rco-odoo left a comment

Choose a reason for hiding this comment

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

Can we please slow down a bit, and take a step back?
What I see coming will make the use of odoo more painful for developers for, and the added value is purely technical. As Odoo developers, we clearly are losing value.
The real problem is not odoo, it's odoo.addons, isn't it?
This really feels like the wrong solution to me.

@kmagusiak
Copy link
Contributor Author

odoo and odoo.addons are now legacy namespace packages which are not supported by all tooling. Removing the __init__.py makes a package a native namespace package. PEP-420.
If we keep the init file in odoo and remove the one from odoo.addons, it will run, still it won't be seen correcly by tooling because odoo is not a native namespace.

Removing the init means we need to do declare these variables elsewhere. Without an init, the order of loading sub-packages of odoo is no longer controlled (not an issue if package dependencies are correct).
/~https://github.com/odoo-dev/odoo/commits/master-packaging-poc-pep420-krma/ - is a POC where variables odoo.XXX are set by another package. However, if you try to from odoo import XXX before that other package is loaded, you will get an error. In any case, you won't have typing information at all since these variables are not declared.

(task-4035335 for more details)

@kmagusiak kmagusiak requested a review from rco-odoo October 28, 2024 15:11
@rco-odoo
Copy link
Member

odoo and odoo.addons are now legacy namespace packages which are not supported by all tooling. Removing the __init__.py makes a package a native namespace package. PEP-420. If we keep the init file in odoo and remove the one from odoo.addons, it will run, still it won't be seen correcly by tooling because odoo is not a native namespace.

Here is the problem that we are trying to solve: we want the addons to be in a native namespace package. This would enable any decent IDE to figure out what from odoo.addons import X actually refers to.

I think that making odoo itself a native namespace package is nonsense, because it was never meant to be like that. This screws up all the imports we are used to do, for completely artificial reasons. And it simply doesn't make sense at the odoo level: you wouldn't distribute odoo.models without odoo.fields, would you?

Can't we find a better solution? What about making odoo_addons an actual namespace package, and simply make odoo.addons a simple alias to it? This would give you the benefits of resolving imports without the artificial changes, wouldn't it? My point here is to challenge the chosen solution, which I find bad.

Removing the init means we need to do declare these variables elsewhere. Without an init, the order of loading sub-packages of odoo is no longer controlled (not an issue if package dependencies are correct). /~https://github.com/odoo-dev/odoo/commits/master-packaging-poc-pep420-krma/ - is a POC where variables odoo.XXX are set by another package. However, if you try to from odoo import XXX before that other package is loaded, you will get an error. In any case, you won't have typing information at all since these variables are not declared.

I am sorry, but all this is about a non-existing problem. The module odoo itself is not perfect, but it's fine.

@kmagusiak
Copy link
Contributor Author

Here is the problem that we are trying to solve: we want the addons to be in a native namespace package. This would enable any decent IDE to figure out what from odoo.addons import X actually refers to.

The thing is that any decent IDE cannot figure out that odoo.addons is a native namespace if odoo is not a native namespace.
I have explored some alternative solutions and all of them required to move a lot of files and/or change nearly all imports in the repository, that's why I did not pursue further things like odoo_addons (for example vscode does not detect odoo.addons... once you put import odoo_addons as addons in the init of odoo).

@kmagusiak kmagusiak changed the title Move SUPERUSER_ID to odoo.api [IMP] Move SUPERUSER_ID to odoo.api Dec 10, 2024
@kmagusiak kmagusiak force-pushed the master-init-superuser-krma branch from 7f5c07b to af3027a Compare December 10, 2024 09:10
kmagusiak added a commit to odoo-dev/upgrade-util that referenced this pull request Dec 10, 2024
@kmagusiak kmagusiak marked this pull request as draft December 10, 2024 09:11
In order to become a native namespace, `odoo` package must not contain
any variables. This is a step in that direction.
odoo.api.SUPERUSER_ID is often used with Environment, so we declare both
in the same package.

task-4069446
@kmagusiak kmagusiak force-pushed the master-init-superuser-krma branch from af3027a to f9d3121 Compare January 7, 2025 11:42
kmagusiak added a commit to odoo-dev/upgrade-util that referenced this pull request Jan 7, 2025
@kmagusiak kmagusiak force-pushed the master-init-superuser-krma branch from f9d3121 to 70ba082 Compare January 7, 2025 11:53
@davidmonnom davidmonnom removed their request for review January 7, 2025 12:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RD research & development, internal work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants