8000 [IMP] core: support reinit modules by HydrionBurst · Pull Request #206408 · odoo/odoo · GitHub
[go: up one dir, main page]

Skip to content

[IMP] core: support reinit modules #206408

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

HydrionBurst
Copy link
Contributor
@HydrionBurst HydrionBurst commented Apr 17, 2025

Before #189000, -i an already installed module will reinitialize the module

  1. reinstall the module without pre/post_init_hook
  2. reinitialize some(but not all) of its direct or indirect dependent installed modules [IMP] core: refactor graph.py #189000 removed the behavior, because it is not correct. As a result, -i does nothing to an installed module.

Although the behavior was not correct and had some side effects, it is useful for developers or a quick database fix.
This commit re-supports the feature and defines the reinit as a special upgrade

  1. doesn't execute migration scripts
  2. load data in 'init' mode
  3. trigger reinitialization for modules directly or indirectly depending on it
operation pre_init_hook/ post_init_hook pre_upgrade/ post_upgrade init_ models load_data
to install yes no yes 'init'
to upgrade no yes yes 'update
registry._reinit_modules no no yes 'init'
registry._force_upgrade_scripts - yes - -

The difference between

operation pre_init_hook/ post_init_hook pre_upgrade/ post_upgrade init_ models load_data loading phase
to install +
registry._force_upgrade_scripts
(by upgrade hacks)
yes yes yes 'init' to install phase
to upgrade +
registry._reinit_modules
(by -i m -u m
which should have same result as -i m)
no yes yes 'init' to upgrade phase

odoo/documentation#13222

Description of the issue/feature this PR addresses:

Current behavior before PR:

Desired behavior after PR is merged:


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

@robodoo
Copy link
Contributor
robodoo commented Apr 17, 2025

Pull request status dashboard

@C3POdoo C3POdoo requested review from a team, Gorash, rco-odoo and Julien00859 and removed request for a team April 17, 2025 09:29
@C3POdoo C3POdoo added the RD research & development, internal work label Apr 17, 2025
@rco-odoo rco-odoo requested review from kmagusiak and removed request for Gorash April 17, 2025 11:52
@kmagusiak
Copy link
Contributor

The code seems ok, although it adds some complexity.

The use case seems hacky to me. Reinitializing the module is quite extreme and seems for development only. Usually, just upgrade is enough during development. You can always dropdb (or uninstall) during development if you want to start from a clean state: reinitalizing could still leave some leftovers. If a module is already installed, nothing should happen.
In conclusion, I think that _reinit_modules is not needed.

@HydrionBurst
Copy link
Contributor Author

Maybe if I have to fix a customer's database, but I am not sure if it is because of modified configurations/data, e.g. security rules, email templates. I can use the reinit feature to rollback those configurations and check if the bug can be reproduced.

Use case from @tde-banana-odoo
when developing in functional modules, having a way to reinit data is really necessary
e.g. testing ACLs changes before / after a specific commit, testing email templates changes, ...
it was the case with -i before, don't care if it is a new command now, just that it is really useful

@HydrionBurst HydrionBurst force-pushed the master-core-reinit-module-cwg branch 2 times, most recently from e542d46 to 9a66cb5 Compare April 18, 2025 10:49
@kmagusiak
Copy link
Contributor

If there is a demand for it, then a new command could be added.

@HydrionBurst HydrionBurst force-pushed the master-core-reinit-module-cwg branch from 9a66cb5 to b1fdc18 Compare April 25, 2025 14:03
@C3POdoo C3POdoo requested review from a team April 25, 2025 14:09
@HydrionBurst HydrionBurst force-pushed the master-core-reinit-module-cwg branch 2 times, most recently from a93bdf0 to 98d77ed Compare April 28, 2025 06:33
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.

LGTM, I like that we expose a dedicated option for that. Don't forget the documentation PR!

  • content/developer/reference/backend/orm/changelog.rst
  • content/developer/reference/cli.rst

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

@robodoo rebase-ff

@robodoo
Copy link
Contributor
robodoo commented May 19, 2025

Merge method set to rebase and fast-forward.

@HydrionBurst HydrionBurst force-pushed the master-core-reinit-module-cwg branch from 5bf68f4 to 2a0e865 Compare May 19, 2025 12:51
@HydrionBurst HydrionBurst force-pushed the master-core-reinit-module-cwg branch from 2a0e865 to 2b38b84 Compare May 19, 2025 13:39
Comment on lines +438 to +444
if reinit_modules:
modules = Module.search([('state', 'in', ('installed', 'to upgrade')), ('name', 'in', tuple(reinit_modules))])
reinit_modules = modules.downstream_dependencies(exclude_states=('uninstalled', 'uninstallable', 'to remove', 'to install')) + modules
registry._reinit_modules.update(m for m in reinit_modules.mapped('name') if m not in graph._imported_modules)
Copy link
Member

Choose a reason for hiding this comment

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

If I understand it correctly, this code ensures that if module A is reinitialized, then all modules that depend on A are reinitialized, too. Am I correct? If so, maybe add a comment line.

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 think the downstream_dependencies can explain the concept well.
And as I worte in the doc of Registry.new and odoo/documentation#13222. The reinit is a simple upgrade nut loading data with 'init' mode, and all mdoules depending on it will also be reinitizlized.

Before odoo#189000, -i an already installed module will reinitialize the
module
1. reinstall the module without ``pre/post_init_hook``
2. reinitialize some(but not all) of its direct or indirect dependent installed
   modules
odoo#189000 removed the behavior, because it is not correct. As a result,
-i does nothing to an installed module.

Although the behavior was not correct and had some side effects, it was useful
for developers or a quick database fix.
This commit re-supports the feature and defines the ```reinit`` as a special
upgrade
1. doesn't execute ``migration scripts``
2. load data in ``'init'`` mode
@HydrionBurst HydrionBurst force-pushed the master-core-reinit-module-cwg branch from 2b38b84 to 5c6ac5d Compare May 23, 2025 13:30
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.

7 participants
0