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

util.modules import fails in pre-migration of base module #175

Closed
lem8r opened this issue Dec 13, 2024 · 2 comments
Closed

util.modules import fails in pre-migration of base module #175

lem8r opened this issue Dec 13, 2024 · 2 comments

Comments

@lem8r
Copy link

lem8r commented Dec 13, 2024

Hi!

When upgrading to 17.0 there is new dependency of custom module that I want to install in pre-migration of base module.
But util.modules is not imported correctly in pre- migration but works in post-.

util.modules.module_installed(cr, 'my_custom_module') gives following error

AttributeError: module 'odoo.modules' has no attribute 'module_installed'

My setup is following:

After upgrading the database from 15.0 to 17.0 via python <(curl -s https://upgrade.odoo.com/upgrade) test -d <your db name> -t <target version>
It is restored to continue migration of custom modules.

Everything happens inside docker container.

Odoo is installed at /usr/lib/python3/dist-packages/odoo
Upgrade util is installed at /usr/local/lib/python3.10/dist-packages/odoo/upgrade via sudo -H pip3 install --upgrade git+https://github.com/odoo/upgrade-util@master

Custom upgrade script is located at /mnt/extra-addons/upgrades/base/16.0.1.3/pre-install_new_deps.py

from odoo.upgrade import util

def migrate(cr, version):
    if util.modules.module_installed(cr, 'my_custom_module'):
        util.modules.new_module_dep(cr, 'my_custom_module', 'new_dep_module')

With psql I reset base version (as it is 17.0.1.3 after upgrade.odoo.com) to trigger our upgrade scripts

update ir_module_module set state='to upgrade', latest_version='15.0.1.3' where name='base';

And start odoo

UPG_AUTOINSTALL='all' odoo -u all -d odoo --upgrade-path=/usr/local/lib/python3.10/dist-packages/odoo/upgrade,/mnt/extra-addons/upgrades --stop-after-init

If I set the breakpoint at upgrade script and check util there it can be seen that modules attribute is imported from odoo modules not from util so the script fails.
However it works in base/0.0.0/post-install_new_deps.py for some reason but it's too late for modules operations.

image
@aj-fuentes
Copy link
Contributor

Do not use submodules directly, they are internal. Always use util.<name_of_function>. In your case this means util.module_installed.

@lem8r
Copy link
Author

lem8r commented Dec 16, 2024

Wow, so simple.
Thank you!

@lem8r lem8r closed this as completed Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants