OCA / openupgradelib

A library with support functions to be called from Odoo migration scripts.
GNU Affero General Public License v3.0
85 stars 171 forks source link

Error migrating from version 9.0 to version 10.0 #339

Closed zamberjo closed 1 year ago

zamberjo commented 1 year ago

I know that these versions are very old but in order to bump to a more current version you must migrate version by version to the desired version.

Describe the bug

The error appears after the merge of https://github.com/OCA/openupgradelib/pull/336.

2023-07-17 05:18:03,199 129 CRITICAL migration odoo.service.server: Failed to initialize database `migration`.
Traceback (most recent call last):
    File "/opt/odoo/custom/src/repos/odoo/odoo/service/server.py", line 974, in preload_registries
      registry = Registry.new(dbname, update_module=update_module)
    File "/opt/odoo/custom/src/repos/odoo/odoo/modules/registry.py", line 83, in new
      odoo.modules.load_modules(registry._db, force_demo, status, update_module)
    File "/opt/odoo/custom/src/repos/odoo/odoo/modules/loading.py", line 375, in load_modules
      report=report, models_to_check=models_to_check, upg_registry=upg_registry)
    File "/opt/odoo/custom/src/repos/odoo/odoo/modules/loading.py", line 211, in load_module_graph
      migrations.migrate_module(package, 'post')
    File "/opt/odoo/custom/src/repos/odoo/odoo/modules/migration.py", line 178, in migrate_module
      mod.migrate(self.cr, installed_version)
    File "/home/odoo/.local/lib/python2.7/site-packages/openupgradelib/openupgrade.py", line 2275, in wrapped_function
      version,
    File "/opt/odoo/custom/src/repos/odoo/odoo/addons/base/migrations/10.0.1.3/post-migration.py", line 142, in migrate
      merge_country_states(env)
    File "/opt/odoo/custom/src/repos/odoo/odoo/addons/base/migrations/10.0.1.3/post-migration.py", line 73, in merge_country_states
      correct_country_states[-1].id,
    File "/home/odoo/.local/lib/python2.7/site-packages/openupgradelib/openupgrade_merge_records.py", line 1003, in merge_records
      _change_generic(*args, method=method)  # pylint: disable=E1124
    File "/home/odoo/.local/lib/python2.7/site-packages/openupgradelib/openupgrade_merge_records.py", line 766, in _change_generic
      if not model._fields.get(model_column) or not model._fields.get(
    UnboundLocalError: local variable 'model' referenced before assignment
pedrobaeza commented 1 year ago

Wait a moment, merge_records was introduced in v11, and it's compatible from that version upwards. If it worked in v10 it was pure luck, but no warranty that is covering all the cases of such version (like all the generic models, or reference fields). I wouldn't use it on 10.0, or I'll study that everything is correct.

MiquelRForgeFlow commented 1 year ago

Selection_1540

pedrobaeza commented 1 year ago

I added it on v11, and I see you put that it's compatible with v10 here:

https://github.com/OCA/openupgradelib/commit/259900c53bbe8914cbe01be56d9d93ed18bbc92e

I don't have such security though, and the test for that is this error, but OK if you want to use it under your risk. I would check again the generic models in such version and the reference fields.