Commit f00c7f5
committed
[FIX] pg: avoid dropping not null constraints in pg18
In PG18 not null constraint names follow the '{table}_{column}_not_null' pattern
as opposed to the '[0-9_]+_not_null' one followed until pg17.
Our utils must be adapted to cope with that, otherwise the util will attempt to
drop not null constraints - failing against those of primary keys.
The following traceback is achieved when trying to upgrade a new demo db in PG18
with `mrp` installed, from 17.0 to 18.0:
```
2025-11-04 10:23:38,126 28873 ERROR test_mrp_17_18.0 odoo.sql_db: bad query: b'ALTER TABLE "mail_push" DROP CONSTRAINT IF EXISTS "mail_notification_web_push_id_not_null" '
ERROR: column "id" is in a primary key
2025-11-04 10:23:38,127 28873 WARNING test_mrp_17_18.0 odoo.modules.loading: Transient module states were reset
2025-11-04 10:23:38,129 28873 ERROR test_mrp_17_18.0 odoo.modules.registry: Failed to load registry
2025-11-04 10:23:38,129 28873 CRITICAL test_mrp_17_18.0 odoo.service.server: Failed to initialize database `test_mrp_17_18.0`.
Traceback (most recent call last):
File "/home/odoo/src/odoo/18.0/odoo/service/server.py", line 1366, in preload_registries
registry = Registry.new(dbname, update_module=update_module)
File "<decorator-gen-13>", line 2, in new
File "/home/odoo/src/odoo/18.0/odoo/tools/func.py", line 97, in locked
return func(inst, *args, **kwargs)
File "/home/odoo/src/odoo/18.0/odoo/modules/registry.py", line 129, in new
odoo.modules.load_modules(registry, force_demo, status, update_module)
File "/home/odoo/src/odoo/18.0/odoo/modules/loading.py", line 485, in load_modules
processed_modules += load_marked_modules(env, graph,
File "/home/odoo/src/odoo/18.0/odoo/modules/loading.py", line 365, in load_marked_modules
loaded, processed = load_module_graph(
File "/home/odoo/src/odoo/18.0/odoo/modules/loading.py", line 182, in load_module_graph
migrations.migrate_module(package, 'pre')
File "/home/odoo/src/odoo/18.0/odoo/modules/migration.py", line 222, in migrate_module
exec_script(self.cr, installed_version, pyfile, pkg.name, stage, stageformat[stage] % version)
File "/home/odoo/src/odoo/18.0/odoo/modules/migration.py", line 259, in exec_script
mod.migrate(cr, installed_version)
File "/home/odoo/src/upgrade/migrations/mail/saas~17.1.1.16/pre-migrate.py", line 30, in migrate
util.rename_model(cr, "mail.notification.web.push", "mail.push")
File "/home/odoo/src/upgrade-util/src/util/models.py", line 308, in rename_model
pg_rename_table(cr, old_table, new_table)
File "/home/odoo/src/upgrade-util/src/util/pg.py", line 1354, in rename_table
remove_constraint(cr, new_table, const, warn=False)
File "/home/odoo/src/upgrade-util/src/util/pg.py", line 853, in remove_constraint
cr.execute(format_query(cr, "ALTER TABLE {} DROP CONSTRAINT IF EXISTS {} {}", table, name, cascade))
File "/home/odoo/src/odoo/18.0/odoo/sql_db.py", line 357, in execute
res = self._obj.execute(query, params)
psycopg2.errors.InvalidTableDefinition: column "id" is in a primary key
```1 parent 92efe24 commit f00c7f5
1 file changed
+17
-12
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1333 | 1333 | | |
1334 | 1334 | | |
1335 | 1335 | | |
1336 | | - | |
1337 | | - | |
| 1336 | + | |
| 1337 | + | |
1338 | 1338 | | |
1339 | | - | |
| 1339 | + | |
1340 | 1340 | | |
1341 | 1341 | | |
1342 | 1342 | | |
1343 | | - | |
| 1343 | + | |
1344 | 1344 | | |
1345 | 1345 | | |
1346 | 1346 | | |
| |||
1353 | 1353 | | |
1354 | 1354 | | |
1355 | 1355 | | |
1356 | | - | |
| 1356 | + | |
1357 | 1357 | | |
1358 | 1358 | | |
1359 | 1359 | | |
1360 | 1360 | | |
1361 | 1361 | | |
1362 | | - | |
1363 | | - | |
| 1362 | + | |
| 1363 | + | |
| 1364 | + | |
| 1365 | + | |
| 1366 | + | |
| 1367 | + | |
| 1368 | + | |
1364 | 1369 | | |
1365 | | - | |
| 1370 | + | |
1366 | 1371 | | |
1367 | 1372 | | |
1368 | | - | |
1369 | | - | |
1370 | | - | |
| 1373 | + | |
| 1374 | + | |
| 1375 | + | |
1371 | 1376 | | |
1372 | 1377 | | |
1373 | | - | |
| 1378 | + | |
1374 | 1379 | | |
1375 | 1380 | | |
1376 | 1381 | | |
| |||
0 commit comments