Repository navigation
Conversation
|
pre-commit failure fixed in OCA/pylint-odoo#590 |
There was a problem hiding this comment.
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.
| new_auto_install_modules = self.browse([]) | ||
| for module in self.env["ir.module.module"].search( | ||
| [ | ||
| ("auto_install", "=", True), | ||
| ("state", "=", "uninstalled"), | ||
| ("name", "not like", ("l10n_%")), | ||
| ] | ||
| ): |
There was a problem hiding this comment.
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.
| 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 |
There was a problem hiding this comment.
thanks, I pushed the condition into the domain though and took the opportunity to rewrite this to Domain syntax
There was a problem hiding this comment.
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.
| 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, | ||
| ) |
There was a problem hiding this comment.
Two things here:
_validate_module_viewsandcreate()call_check_xmlon several views, soself.xml_idin the handler raisesExpected singletonand aborts the upgrade instead of logging.- As
_raise_view_errordoesn't raise anymore, validation goes on and fails later withAttributeError/KeyError/NameError/ValueError(_check_field_paths,_validate_domain_identifiers).
| 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, | |
| ) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
_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.
|
The following commit authors need to sign the Contributor License Agreement: |
dc4f15f to
229928f
Compare
|
@daiduongnguyen-odoo @kafai-lam @royle-vietnam I see that your CLA is not updated properly. can you sign it again 🙏 ? |
carlosdauden
left a comment
There was a problem hiding this comment.
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:
- Custom view diagnostics are gone. With
_check_xmlas 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)insidetry/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.
-
test_03_update_listdoes not test the new country filter:auto_install_country_specifichas nocountry_ids, and itsl10n_name is already excluded by the name filter. Please add a non-l10n module withcountry_idsof a country no company uses (must stay uninstalled) and one with the main company's country (must be installed). -
pre-commit: the pylint-odoo crash on
odoo_patch/odoo/modules/module_graph.pyis fixed in OCA/pylint-odoo#590, which is released in v10.0.12..pre-commit-config.yamlstill pinsv10.0.11; bumping it makes the check green.
Not blocking, can be follow-ups:
- The
l10n_%exclusion inupdate_listis now redundant and costs features. Every auto_installl10n_*module in 20.0 either declarescountries(handled by the new filter, the same rule asbutton_install) or depends on anotherl10n_*module (I checked all 189: none has neither). Meanwhile it skips bridges a fresh 20.0 database gets: new in 20.0 arel10n_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. update_listalso 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 whoseir.module.modulerow did not exist beforeupdate_list()(take the names before calling the original), and log the list of modules it installs either way.update_listchecks alldependencies_id, while core only looks at theauto_install_requiredones. No module new in 20.0 has a partialauto_installlist, so this changes nothing today; a comment would help the next port.- Nit: the
check_external_dependenciespatch looks dead in 20.0. It returns early throughManifest.for_addon()when the module is not available, and an unknown dependency raisesUserErrorin_state_updatebefore. I could not find a path that raisesAttributeErrorany more. - 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 useno_version=True. We hit this twice in 20.0 scripts (fleet_maintenance,account_payment_custom). - Outside this PR, but needed before #6068: base's
load_datafails 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__.pysettingconvert_xml_import/convert_csv_importfromodoo.tools.convertwhen missing) unblocks it. - The CLA check fails because of the old history commits of two Viindoo authors (v17 port,
_raise_view_errorchanges); etobella already pinged them.
carlosdauden
left a comment
There was a problem hiding this comment.
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.pyis fixed in OCA/pylint-odoo#590, released in v10.0.12..pre-commit-config.yamlstill pinsv10.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_errorchanges); etobella already pinged them.
|
|
||
|
|
||
| def _check_xml(self): | ||
| """Don't do any view validation, as it will mostly fail during upgrades""" |
There was a problem hiding this comment.
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.
| 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 |
There was a problem hiding this comment.
For the _validate_custom_views patch below.
| import logging | |
| import logging | |
| from contextvars import ContextVar |
|
|
||
|
|
||
| _check_xml._original_method = IrUiView._check_xml | ||
| IrUiView._check_xml = _check_xml |
There was a problem hiding this comment.
Registration of the _validate_custom_views patch.
| 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 |
| auto_install_country_specific = IrModuleModule.create( | ||
| { | ||
| "name": "l10n_openupgrade_framework_auto_install_country_specific", | ||
| "state": "uninstalled", | ||
| "auto_install": "true", |
There was a problem hiding this comment.
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).
| 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") |
There was a problem hiding this comment.
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).
| 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) |
There was a problem hiding this comment.
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.
| ), | ||
| ] | ||
| ) | ||
| ): |
There was a problem hiding this comment.
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.
| ): | |
| ): | |
| # 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 |
| 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 |
There was a problem hiding this comment.
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> | ||
| ``` |
There was a problem hiding this comment.
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).
| ``` | |
| ``` | |
| 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 | |||
There was a problem hiding this comment.
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))| from . import addons, modules, orm | |
| from . import addons, modules, orm, tools |
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.
…run scripts" This reverts commit 576daf1.
…path does not exist
Co-authored-by: FerDeNetlab <[email protected]>
Co-authored-by: FerDeNetlab <[email protected]>
when installing auto_install modules
229928f to
e98589a
Compare
depends on: