Skip to content

[20.0][MIG] openupgrade_framework - #6046

Open
hbrunn wants to merge 70 commits into
OCA:20.0from
hbrunn:20.0-mig-openupgrade_framework
Open

hbrunn wants to merge 70 commits into
OCA:20.0from
hbrunn:20.0-mig-openupgrade_framework

Conversation

@hbrunn

@hbrunn hbrunn commented Sep 29, 2026 •

Copy link
Copy Markdown
Member

@OCA-git-bot OCA-git-bot added mod:openupgrade_scripts Module openupgrade_scripts mod:openupgrade_framework Module openupgrade_framework series:20.0 labels Sep 29, 2026
@hbrunn hbrunn mentioned this pull request Sep 29, 2026
3 of 7 tasks
@hbrunn hbrunn added this to the 20.0 milestone Sep 29, 2026
@hbrunn

hbrunn commented Sep 29, 2026

Copy link
Copy Markdown
Member Author

pre-commit failure fixed in OCA/pylint-odoo#590

@FerDeNetlab FerDeNetlab left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Tested on a 19.0 db with crm, sale_management, purchase, stock, account + l10n_mx, project, hr, mrp and point_of_sale (131 modules after the upgrade). These are the framework issues we hit, one per comment so you can take what makes sense.

Drafted with AI assistance (Claude Opus 5.5), reviewed by me; each suggestion was checked against the current code of this PR and our test migration.

Comment on lines +17 to +24
new_auto_install_modules = self.browse([])
for module in self.env["ir.module.module"].search(
[
("auto_install", "=", True),
("state", "=", "uninstalled"),
("name", "not like", ("l10n_%")),
]
):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

button_install skips auto_install modules whose country_ids don't match any company, this loop doesn't, so e.g. account_peppol gets installed on databases without a Peppol country.

Suggested change
new_auto_install_modules = self.browse([])
for module in self.env["ir.module.module"].search(
[
("auto_install", "=", True),
("state", "=", "uninstalled"),
("name", "not like", ("l10n_%")),
]
):
new_auto_install_modules = self.browse([])
company_countries = self.env["res.company"].sudo().search([]).country_id
for module in self.env["ir.module.module"].search(
[
("auto_install", "=", True),
("state", "=", "uninstalled"),
("name", "not like", ("l10n_%")),
]
):
# same rule as button_install
if module.country_ids and not module.country_ids & company_countries:
continue

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

thanks, I pushed the condition into the domain though and took the opportunity to rewrite this to Domain syntax

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The domain looks right to me, but test_03_update_list doesn't cover it yet: its country specific module has no country_ids and an l10n_ name, already excluded by the name filter. I left a suggestion on the test with a module of a country no company uses and one of the company's country.

Comment on lines +19 to +30
try:
return IrUiView._check_xml._original_method(self)
except ValidationError as e:
_logger.warning(
"Can't render custom view %s for model %s. "
"Assuming you are migrating between major versions of Odoo. "
"Please review the view contents manually after the migration.\n"
"Error: %s",
self.xml_id,
self.model,
e,
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Two things here:

  • _validate_module_views and create() call _check_xml on several views, so self.xml_id in the handler raises Expected singleton and aborts the upgrade instead of logging.
  • As _raise_view_error doesn't raise anymore, validation goes on and fails later with AttributeError/KeyError/NameError/ValueError (_check_field_paths, _validate_domain_identifiers).
Suggested change
try:
return IrUiView._check_xml._original_method(self)
except ValidationError as e:
_logger.warning(
"Can't render custom view %s for model %s. "
"Assuming you are migrating between major versions of Odoo. "
"Please review the view contents manually after the migration.\n"
"Error: %s",
self.xml_id,
self.model,
e,
)
for view in self:
try:
IrUiView._check_xml._original_method(view)
# with _raise_view_error not raising, validation can fail later on
except (
ValidationError,
ValueError,
AttributeError,
KeyError,
NameError,
) as e:
_logger.warning(
"Can't render custom view %s for model %s. "
"Assuming you are migrating between major versions of Odoo. "
"Please review the view contents manually after the migration.\n"
"Error: %s",
view.xml_id,
view.model,
e,
)

@hbrunn hbrunn Nov 3, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

here I've disabled _check_xml completely, as it doesn't add anything interesting to the log. we get all the info we need from _raise_view_error. Then we also don't need to patch away a plethora of followup issues like in _check_field_paths

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

_raise_view_error covers the views checked while the modules load, but with _check_xml a no-op it is never reached for the custom views either, which core validates once at the end (STEP 6, _validate_custom_views): our run logs 0 "Can't render custom view" lines, against 1813 with the previous version. I left a suggestion on the current code that keeps _check_xml off while the modules load and only validates the custom views at STEP 6, one by one, logging instead of raising.

@oca-cla-bot

oca-cla-bot Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

The following commit authors need to sign the Contributor License Agreement:

CLA not signed

@OCA-git-bot OCA-git-bot removed the mod:openupgrade_scripts Module openupgrade_scripts label Nov 3, 2026
@hbrunn
hbrunn force-pushed the 20.0-mig-openupgrade_framework branch from dc4f15f to 229928f Compare November 3, 2026 11:04
@etobella

etobella commented Nov 3, 2026

Copy link
Copy Markdown
Member

@daiduongnguyen-odoo @kafai-lam @royle-vietnam I see that your CLA is not updated properly. can you sign it again 🙏 ?

@carlosdauden carlosdauden left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Tested by merging it into our 20.0 integration branch: the 19.0 -> 20.0 migration of the OCA test database with ~420 module scripts on top passes, with 130 migration tests (run with the same test-migration workflow, Python 3.12 / PostgreSQL 16). Thanks for taking FerDeNetlab's suggestions (attachments of removed models, country filter, savepoint in unlink): I checked all three against origin/20.0 and they are right.

Changes I would ask for:

  1. Custom view diagnostics are gone. With _check_xml as a no-op, nothing reports broken views any more: our run logs 0 "Can't render custom view" lines, against 1813 with the previous version of this PR (19.0 also logged them). Most of those 1813 were noise from standard views checked before their module was updated, so I agree with not validating while the modules load. But core's STEP 6 (odoo/modules/loading.py: View._validate_custom_views(model) inside try/except Exception) validates exactly the views a migrator has to fix by hand (no xmlid, __export__, studio), once, at the end, and never aborts. Now that goes through the no-op too. Suggestion, keeping your approach for everything else (tested on our branch: unchanged result on the OCA test database, 0 warnings, and with one custom view adding a field removed in 20.0, the migration still ends fine and STEP 6 reports that view and the other broken elements of the same inheritance tree, right before "Modules loaded"):
from contextvars import ContextVar

# _validate_custom_views replaces the context of the views it checks
# (with_context({'load_all_views': True})), so a context key would not get through
_validating_custom_views = ContextVar(
    "openupgrade_validating_custom_views", default=False
)


def _check_xml(self):
    """Don't validate views while the modules are loading; only validate
    custom views, one by one, at the end of the upgrade (core STEP 6)"""
    if not _validating_custom_views.get():
        return
    for view in self:
        try:
            _check_xml._original_method(view)
        except Exception as e:  # pylint: disable=broad-except
            _logger.warning(
                "Custom view %s (%s) of model %s is invalid after the migration, "
                "review it manually: %s",
                view.id, view.xml_id or view.name, view.model, e,
            )


def _validate_custom_views(self, model):
    token = _validating_custom_views.set(True)
    try:
        return _validate_custom_views._original_method(self, model)
    finally:
        _validating_custom_views.reset(token)

Most problems are still logged by your _raise_view_error patch; the loop catches the rest (for example the attrs/states ValidationError, or a follow-up AttributeError after _raise_view_error returned), without hiding the other views of the model. A test could create a custom view with an unknown field (creation passes, _check_xml is off) and check that _validate_custom_views("res.partner") logs it.

  1. test_03_update_list does not test the new country filter: auto_install_country_specific has no country_ids, and its l10n_ name is already excluded by the name filter. Please add a non-l10n module with country_ids of a country no company uses (must stay uninstalled) and one with the main company's country (must be installed).

  2. pre-commit: the pylint-odoo crash on odoo_patch/odoo/modules/module_graph.py is fixed in OCA/pylint-odoo#590, which is released in v10.0.12. .pre-commit-config.yaml still pins v10.0.11; bumping it makes the check green.

Not blocking, can be follow-ups:

  1. The l10n_% exclusion in update_list is now redundant and costs features. Every auto_install l10n_* module in 20.0 either declares countries (handled by the new filter, the same rule as button_install) or depends on another l10n_* module (I checked all 189: none has neither). Meanwhile it skips bridges a fresh 20.0 database gets: new in 20.0 are l10n_fr_payment, l10n_kr_sale, l10n_eg_edi_pos, l10n_bh_pos, l10n_fr_pdp_penalty_rate. Dropping the name filter would give migrated databases the same modules as new ones.
  2. update_list also re-installs auto_install modules the user uninstalled on purpose in the old version (any uninstalled auto_install module whose dependencies are installed qualifies, not only modules new in this version). That has been so since 18.0, so not for this PR, but consider limiting it to modules whose ir.module.module row did not exist before update_list() (take the names before calling the original), and log the list of modules it installs either way.
  3. update_list checks all dependencies_id, while core only looks at the auto_install_required ones. No module new in 20.0 has a partial auto_install list, so this changes nothing today; a comment would help the next port.
  4. Nit: the check_external_dependencies patch looks dead in 20.0. It returns early through Manifest.for_addon() when the module is not available, and an unknown dependency raises UserError in _state_update before. I could not find a path that raises AttributeError any more.
  5. DEVELOP.md: worth a line saying that, since the framework force-runs the scripts of modules installed during the upgrade, those scripts get an empty version, so @openupgrade.migrate() skips them unless they use no_version=True. We hit this twice in 20.0 scripts (fleet_maintenance, account_payment_custom).
  6. Outside this PR, but needed before #6068: base's load_data fails on 20.0 until OCA/openupgradelib#468 is merged (it is approved by two maintainers) and installed by the workflow. Otherwise a small shim in the framework (odoo_patch/odoo/tools/__init__.py setting convert_xml_import/convert_csv_import from odoo.tools.convert when missing) unblocks it.
  7. The CLA check fails because of the old history commits of two Viindoo authors (v17 port, _raise_view_error changes); etobella already pinged them.

@carlosdauden carlosdauden left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

As asked, the remaining points of my previous review as line comments, checked again on 229928f. The suggestions come from our 20.0 integration branch (this PR + #6068 + our module scripts), where the 19.0 -> 20.0 migration of the OCA test database passes with 132 migration tests. Applied together on 229928f (plus the new odoo_patch/odoo/tools/__init__.py), the framework tests pass; the new test_03 cases fail without the country filter and test_04 fails without the _validate_custom_views patch.

Two points have no line in the diff:

  • pre-commit: the pylint-odoo crash on odoo_patch/odoo/modules/module_graph.py is fixed in OCA/pylint-odoo#590, released in v10.0.12. .pre-commit-config.yaml still pins v10.0.11; bumping it makes the check green.
  • The CLA check fails because of the old history commits of two Viindoo authors (v17 port, _raise_view_error changes); etobella already pinged them.

Comment on lines +12 to +15


def _check_xml(self):
"""Don't do any view validation, as it will mostly fail during upgrades"""

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Custom view diagnostics are gone: with _check_xml a no-op nothing reports broken views any more. Our run logs 0 "Can't render custom view" lines, against 1813 with the previous version of this PR (19.0 also logged them). Most of those 1813 were noise from standard views checked before their module was updated, so I agree with not validating while the modules load. But core's STEP 6 (odoo/modules/loading.py: View._validate_custom_views(model) inside try/except Exception) validates exactly the views a migrator has to fix by hand (no xmlid, __export__, studio), once, at the end, and never aborts; now that goes through the no-op too.

This keeps your approach for everything else and only validates custom views at STEP 6, one by one, so one broken view does not hide the others of the model. Most problems are still logged by your _raise_view_error patch; the loop catches the rest (the attrs/states ValidationError, or a follow-up AttributeError after _raise_view_error returned). A context key would not do: _validate_custom_views replaces the context (with_context({'load_all_views': True})). Tested on our branch: unchanged result on the OCA test database, and with a custom view adding a field removed in 20.0 the migration still ends fine and STEP 6 reports that view right before "Modules loaded". Needs the import and the registration below, and there is a test for it in test_openupgrade_framework.py.

Suggested change
def _check_xml(self):
"""Don't do any view validation, as it will mostly fail during upgrades"""
# Set while core STEP 6 validates the custom views of a model. A context key
# would not do: _validate_custom_views replaces the context of the views it
# checks (with_context({'load_all_views': True})).
_validating_custom_views = ContextVar(
"openupgrade_validating_custom_views", default=False
)
def _check_xml(self):
"""Don't validate views while the modules are loading: most failures are
standard views checked before their own module is updated. Only validate
custom views, one by one, at the end of the upgrade (core STEP 6), and log
the ones that need a manual review."""
if not _validating_custom_views.get():
return
for view in self:
try:
_check_xml._original_method(view)
except Exception as e: # noqa: BLE001 # pylint: disable=broad-except
_logger.warning(
"Custom view %s (%s) of model %s is invalid after the migration, "
"review it manually: %s",
view.id,
view.xml_id or view.name,
view.model,
e,
)
def _validate_custom_views(self, model):
"""Let _check_xml validate the custom views of the model"""
token = _validating_custom_views.set(True)
try:
return _validate_custom_views._original_method(self, model)
finally:
_validating_custom_views.reset(token)

# Copyright 2024 Viindoo Technology Joint Stock Company (Viindoo)
# Copyright Odoo Community Association (OCA)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import logging

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

For the _validate_custom_views patch below.

Suggested change
import logging
import logging
from contextvars import ContextVar



_check_xml._original_method = IrUiView._check_xml
IrUiView._check_xml = _check_xml

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Registration of the _validate_custom_views patch.

Suggested change
IrUiView._check_xml = _check_xml
IrUiView._check_xml = _check_xml
_validate_custom_views._original_method = IrUiView._validate_custom_views
IrUiView._validate_custom_views = _validate_custom_views

Comment on lines +80 to +84
auto_install_country_specific = IrModuleModule.create(
{
"name": "l10n_openupgrade_framework_auto_install_country_specific",
"state": "uninstalled",
"auto_install": "true",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

test_03_update_list does not test the new country filter: auto_install_country_specific has no country_ids, and its l10n_ name is already excluded by the name filter. This checks both sides: a module of a country no company uses stays uninstalled, one of the company's country is installed (both fail without the filter).

Suggested change
auto_install_country_specific = IrModuleModule.create(
{
"name": "l10n_openupgrade_framework_auto_install_country_specific",
"state": "uninstalled",
"auto_install": "true",
companies_countries = self.env["res.company"].search([]).country_id
other_country = self.env["res.country"].search(
[("id", "not in", companies_countries.ids)], limit=1
)
auto_install_other_country = IrModuleModule.create(
{
"name": "openupgrade_framework_test_auto_install_other_country",
"state": "uninstalled",
"auto_install": "true",
"country_ids": [fields.Command.set(other_country.ids)],
"dependencies_id": [
fields.Command.create({"name": base.name}),
],
}
)
self.env.company.country_id = self.env.ref("base.be")
auto_install_company_country = IrModuleModule.create(
{
"name": "openupgrade_framework_test_auto_install_company_country",
"state": "uninstalled",
"auto_install": "true",
"country_ids": [fields.Command.set(self.env.ref("base.be").ids)],

self.env["ir.module.module"].update_list()
self.assertEqual(auto_install.state, "to install")
self.assertEqual(auto_install_localization.state, "uninstalled")
self.assertEqual(auto_install_country_specific.state, "uninstalled")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Asserts for the modules above, and a test for the _validate_custom_views suggestion in ir_ui_view.py: creating the invalid view passes because _check_xml is off, and STEP 6 logs it instead of raising (it fails without the patch).

Suggested change
self.assertEqual(auto_install_country_specific.state, "uninstalled")
self.assertEqual(auto_install_other_country.state, "uninstalled")
self.assertEqual(auto_install_company_country.state, "to install")
def test_04_validate_custom_views(self):
"""
Test that custom views are only validated at the end of the upgrade (core
STEP 6), and that invalid ones are logged instead of failing
"""
self.env["ir.ui.view"].create(
{
"model": "res.partner",
"arch": '<form><field name="nonexisting_field" /></form>',
}
)
with self.assertLogs(
"odoo.addons.openupgrade_framework.odoo_patch.odoo.addons.base.models.ir_ui_view",
"WARNING",
):
self.env["ir.ui.view"]._validate_custom_views("res.partner")

installed.
Ignore localization modules that are set to auto_install
"""
result = IrModuleModule.update_list._original_method(self)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Not for this PR, it has been so since 18.0: this also re-installs auto_install modules the user uninstalled on purpose in the old version, since any uninstalled auto_install module whose dependencies are installed qualifies, not only the modules new in this version. Consider limiting it to modules whose ir.module.module row did not exist before this call (take the names before calling the original), and logging the list of modules it installs either way.

),
]
)
):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Not blocking: this checks all dependencies_id, while core only looks at the auto_install_required ones. No module new in 20.0 has a partial auto_install list, so it changes nothing today; a comment would help the next port.

Suggested change
):
):
# core (button_install) only requires the auto_install_required
# dependencies; no module new in 20.0 has a partial auto_install list,
# so checking all of them gives the same result for now

Comment on lines +48 to +55
def check_external_dependencies(self, module_name, newstate="to install"):
try:
IrModuleModule.check_external_dependencies._original_method(
self, module_name, newstate=newstate
)
except AttributeError: # pylint: disable=except-pass
# this happens when a module is installed that doesn't exist in the new version
pass

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nit: this patch looks dead in 20.0. check_external_dependencies returns early through Manifest.for_addon() when the module is not available, and an unknown dependency raises UserError in _state_update before. I could not find a path that raises AttributeError any more.

# <OpenUpgrade:REMOVE>
# Comment the code, instead of removing it.
# </OpenUpgrade>
```

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Worth a line: since the framework force-runs the scripts of modules installed during the upgrade, those scripts get an empty version, so @openupgrade.migrate() skips them unless they use no_version=True. We hit this twice in 20.0 scripts (fleet_maintenance, account_payment_custom).

Suggested change
```
```
The framework also runs the migration scripts of the modules installed
during the upgrade (new modules, auto_install bridges, modules a script
marks as to install). Their installed version is empty, so
`@openupgrade.migrate()` skips them: use
`@openupgrade.migrate(no_version=True)` in those scripts.

@@ -0,0 +1 @@
from . import addons, modules, orm

@carlosdauden carlosdauden Nov 10, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Outside this PR: base's load_data needs OCA/openupgradelib#468 on 20.0, merged today, so test-migration.yml (openupgradelib from master) is fine now. Until a release includes it, requirements.txt still gets PyPI 3.13.7 with the old load_data; if you want to cover that, a small shim in the framework does it, odoo_patch/odoo/tools/__init__.py (a new file, so it can't go in a suggestion):

# Copyright Odoo Community Association (OCA)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
"""Odoo 20.0 no longer re-exports the whole odoo.tools.convert module from
odoo.tools (only convert_file), but openupgradelib's load_data still calls
odoo.tools.convert_xml_import and odoo.tools.convert_csv_import. Expose them
again so load_data works with 20.0."""

from odoo import tools
from odoo.tools import convert

for _name in ("convert_xml_import", "convert_csv_import"):
    if not hasattr(tools, _name):
        setattr(tools, _name, getattr(convert, _name))
Suggested change
from . import addons, modules, orm
from . import addons, modules, orm, tools

legalsylvain and others added 10 commits November 24, 2026 18:16
If we don't include it, /jsonrpc route doesn't work.
If you have a module in previous versions that adds data on a model,
and such model is not loaded in the registry in current version because
the module is absent in it, you can't uninstall such module, getting
this error:

  File "odoo/odoo/addons/base/models/ir_model.py", line 1945, in _module_data_uninstall
    delete(self.env[model].browse(item[1] for item in items))
  File "odoo/odoo/api.py", line 463, in __getitem__
    return self.registry[model_name]._browse(self, (), ())
  File "odoo/odoo/modules/registry.py", line 177, in __getitem__
    return self.models[model_name]
KeyError: 'model'

With this patch, data cleanup of such model is skipped and there's no crash.
chienandalu and others added 29 commits November 24, 2026 18:16
when installing auto_install modules
@hbrunn
hbrunn force-pushed the 20.0-mig-openupgrade_framework branch from 229928f to e98589a Compare November 24, 2026 17:16

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:openupgrade_framework Module openupgrade_framework series:20.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.