odoo/upgrade-util#338

Created by Sanchit Gupta (sagu)
Merged at 3e22c9a75d19564f3c4915699937f689f3d3d809

Statuses:

label
odoo-dev:master-fix_constraint_automation-sagu
head
c805d65889914ee20d1ab36ac54a831251270e61
merged
1 month ago by Upgrade, Christophe Simonis (chs)
odoo/upgrade-util
master #338

[FIX] util/models: Fix constrain voilation

before 16.5 there was constraint on field action_server_id of base.automation model ON delete restrict which causing issue during upgrade when removing model if contextual action created for the same server action binding_model_id as below mentioned traceback because due to on delete cascade model will remove.So, server action will also delete. But server action is linked to automated action. So, request will block.

For fixing this issue removing the automated action first and then let the model remove.

Traceback (most recent call last):
  File "/home/odoo/src/odoo/16.0/odoo/service/server.py", line 1333, in preload_registries
    registry = Registry.new(dbname, update_module=update_module)
  File "<decorator-gen-16>", line 2, in new
  File "/home/odoo/src/odoo/16.0/odoo/tools/func.py", line 87, in locked
    return func(inst, *args, **kwargs)
  File "/home/odoo/src/odoo/16.0/odoo/modules/registry.py", line 87, in new
    odoo.modules.load_modules(registry, force_demo, status, update_module)
  File "/home/odoo/src/odoo/16.0/odoo/modules/loading.py", line 528, in load_modules
    migrations.migrate_module(package, 'end')
  File "/home/odoo/src/odoo/16.0/odoo/modules/migration.py", line 170, in migrate_module
    exec_script(self.cr, installed_version, pyfile, pkg.name, stage, stageformat[stage] % version)
  File "/home/odoo/src/odoo/16.0/odoo/modules/migration.py", line 188, in exec_script
    migrate(cr, installed_version)
  File "/tmp/tmpegkppsuy/migrations/sale_subscription/saas~15.3.1.1/end-migrate.py", line 20, in migrate
    util.remove_model(cr, "sale.subscription.line", drop_table=False)
  File "/tmp/tmpegkppsuy/migrations/util/models.py", line 222, in remove_model
    cr.execute("DELETE FROM ir_model WHERE id=%s", (mod_id,))
  File "/home/odoo/src/odoo/16.0/odoo/sql_db.py", line 324, in execute
    res = self._obj.execute(query, params)
psycopg2.errors.ForeignKeyViolation: update or delete on table "ir_act_server" violates foreign key constraint "base_automation_action_server_id_fkey" on table "base_automation"
DETAIL:  Key (id)=(3632) is still referenced from table "base_automation".

upg-3179507
opw-5148694