Skip to content

Commit 97752c5

Browse files
yajoEmilioPascual
andcommitted
[FIX]: allow migrating tables without primary index
During a migration from v12 to v13, this fixes this error: ``` 2024-06-12 12:28:54,522 825 CRITICAL db_1732812 odoo.service.server: Failed to initialize database `db_1732812`. Traceback (most recent call last): File "/home/odoo/src/odoo/13.0/odoo/service/server.py", line 1194, in preload_registries registry = Registry.new(dbname, update_module=update_module) File "/home/odoo/src/odoo/13.0/odoo/modules/registry.py", line 87, in new odoo.modules.load_modules(registry._db, force_demo, status, update_module) File "/home/odoo/src/odoo/13.0/odoo/modules/loading.py", line 424, in load_modules force, status, report, loaded_modules, update_module, models_to_check) File "/home/odoo/src/odoo/13.0/odoo/modules/loading.py", line 315, in load_marked_modules perform_checks=perform_checks, models_to_check=models_to_check File "/home/odoo/src/odoo/13.0/odoo/modules/loading.py", line 177, in load_module_graph migrations.migrate_module(package, 'pre') File "/home/odoo/src/odoo/13.0/odoo/modules/migration.py", line 186, in migrate_module migrate(self.cr, installed_version) File "/tmp/tmprdd50vnu/migrations/mass_mailing/saas~12.5.2.0/pre-10-models.py", line 21, in migrate util.rename_model(cr, "mail.mass_mailing.list_contact_rel", "mailing.contact.subscription") File "/tmp/tmprdd50vnu/migrations/util/models.py", line 236, in rename_model table_of_model(cr, new), File "/tmp/tmprdd50vnu/migrations/util/pg.py", line 1051, in rename_table (old_pkey,) = cr.fetchone() TypeError: 'NoneType' object is not iterable ``` @moduon MT-6161 closes #96 Signed-off-by: Christophe Simonis (chs) <[email protected]> Co-authored-by: Emilio Pascual <[email protected]>
1 parent 5b944f7 commit 97752c5

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/util/pg.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,9 +1048,12 @@ def rename_table(cr, old_table, new_table, remove_constraints=True):
10481048
""",
10491049
[new_table],
10501050
)
1051-
(old_pkey,) = cr.fetchone()
1052-
new_pkey = new_table + "_pkey"
1053-
cr.execute(sql.SQL("ALTER INDEX {} RENAME TO {}").format(sql.Identifier(old_pkey), sql.Identifier(new_pkey)))
1051+
if cr.rowcount:
1052+
(old_pkey,) = cr.fetchone()
1053+
new_pkey = new_table + "_pkey"
1054+
cr.execute(sql.SQL("ALTER INDEX {} RENAME TO {}").format(sql.Identifier(old_pkey), sql.Identifier(new_pkey)))
1055+
else:
1056+
new_pkey = "" # no PK renamed
10541057

10551058
# rename indexes (except the pkey's one and those not containing $old_table)
10561059
cr.execute(

0 commit comments

Comments
 (0)