Skip to content

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

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

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
aj-fuentes added a commit to odoo/documentation that referenced this issue May 23, 2025
The full module path in upgrade utils docs causes confusion for users.
See issues odoo/upgrade-util#272 and odoo/upgrade-util#175.

All utils we document online should be used via the top-level module
--i.e. `util.name` instead of `util.submodule.name`

Stripping the module path can be achieved in the configuration with
[`add_module_name=False`](https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-add_module_names)
Unfortunately this is a global setting that could affect other parts of
Odoo documentation. Thus in current patch we strip the module path from
the signature of `odoo.upgrade.util` functions and classes.

Technical links:
https://www.sphinx-doc.org/en/master/extdev/event_callbacks.html#event-object-description-transform
https://www.sphinx-doc.org/en/master/extdev/nodes.html#sphinx.addnodes.desc_signature
https://github.com/sphinx-doc/sphinx/blob/v4.3.2/sphinx/domains/python.py#L512
https://sphinx-docutils.readthedocs.io/en/latest/docutils.nodes.html#docutils.nodes
aj-fuentes added a commit to odoo/documentation that referenced this issue May 23, 2025
The full module path in upgrade utils docs causes confusion for users.
See issues odoo/upgrade-util#272 and odoo/upgrade-util#175.

All utils we document online should be used via the top-level module
--i.e. `util.name` instead of `util.submodule.name`

Stripping the module path can be achieved in the configuration with
[`add_module_name=False`](https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-add_module_names)
Unfortunately this is a global setting that could affect other parts of
Odoo documentation. Thus in current patch we strip the module path from
the signature of `odoo.upgrade.util` functions and classes.

Technical links:
https://www.sphinx-doc.org/en/master/extdev/event_callbacks.html#event-object-description-transform
https://www.sphinx-doc.org/en/master/extdev/nodes.html#sphinx.addnodes.desc_signature
https://github.com/sphinx-doc/sphinx/blob/v4.3.2/sphinx/domains/python.py#L512
https://sphinx-docutils.readthedocs.io/en/latest/docutils.nodes.html#docutils.nodes
robodoo pushed a commit to odoo/documentation that referenced this issue May 23, 2025
The full module path in upgrade utils docs causes confusion for users.
See issues odoo/upgrade-util#272 and odoo/upgrade-util#175.

All utils we document online should be used via the top-level module
--i.e. `util.name` instead of `util.submodule.name`

Stripping the module path can be achieved in the configuration with
[`add_module_name=False`](https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-add_module_names)
Unfortunately this is a global setting that could affect other parts of
Odoo documentation. Thus in current patch we strip the module path from
the signature of `odoo.upgrade.util` functions and classes.

Technical links:
https://www.sphinx-doc.org/en/master/extdev/event_callbacks.html#event-object-description-transform
https://www.sphinx-doc.org/en/master/extdev/nodes.html#sphinx.addnodes.desc_signature
https://github.com/sphinx-doc/sphinx/blob/v4.3.2/sphinx/domains/python.py#L512
https://sphinx-docutils.readthedocs.io/en/latest/docutils.nodes.html#docutils.nodes

closes #13519

Signed-off-by: Victor Feyens (vfe) <[email protected]>
fw-bot pushed a commit to odoo/documentation that referenced this issue May 23, 2025
The full module path in upgrade utils docs causes confusion for users.
See issues odoo/upgrade-util#272 and odoo/upgrade-util#175.

All utils we document online should be used via the top-level module
--i.e. `util.name` instead of `util.submodule.name`

Stripping the module path can be achieved in the configuration with
[`add_module_name=False`](https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-add_module_names)
Unfortunately this is a global setting that could affect other parts of
Odoo documentation. Thus in current patch we strip the module path from
the signature of `odoo.upgrade.util` functions and classes.

Technical links:
https://www.sphinx-doc.org/en/master/extdev/event_callbacks.html#event-object-description-transform
https://www.sphinx-doc.org/en/master/extdev/nodes.html#sphinx.addnodes.desc_signature
https://github.com/sphinx-doc/sphinx/blob/v4.3.2/sphinx/domains/python.py#L512
https://sphinx-docutils.readthedocs.io/en/latest/docutils.nodes.html#docutils.nodes

X-original-commit: 541c9d4
aj-fuentes added a commit to odoo/documentation that referenced this issue May 23, 2025
The full module path in upgrade utils docs causes confusion for users.
See issues odoo/upgrade-util#272 and odoo/upgrade-util#175.

All utils we document online should be used via the top-level module
--i.e. `util.name` instead of `util.submodule.name`

Stripping the module path can be achieved in the configuration with
[`add_module_name=False`](https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-add_module_names)
Unfortunately this is a global setting that could affect other parts of
Odoo documentation. Thus in current patch we strip the module path from
the signature of `odoo.upgrade.util` functions and classes.

Technical links:
https://www.sphinx-doc.org/en/master/extdev/event_callbacks.html#event-object-description-transform
https://www.sphinx-doc.org/en/master/extdev/nodes.html#sphinx.addnodes.desc_signature
https://github.com/sphinx-doc/sphinx/blob/v4.3.2/sphinx/domains/python.py#L512
https://sphinx-docutils.readthedocs.io/en/latest/docutils.nodes.html#docutils.nodes

X-original-commit: 541c9d4
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