-
- Downloads
[FIX] core: fix remove constraints at uninstall
This patch aims to fix multiple issues with the removal of table
constraints at module uninstall.
1. We cannot remove `ir.model.constraint` records before calling
`_module_data_uninstall` on them. Otherwise we either won't find them
when performing the search
`self.env['ir.model.constraint'].search([('module', 'in',
modules.ids)]` or, if we somehow keep the ids and use `browse`
instead, would get an error because `_module_data_uninstall` tries to
access field values of records already removed. Note, although not an
issue, the removal is redundant for non FK constraints since
`_model_data_uninstall` already unlinks the record.
2. When a constraint has a name longer than 63 characters (Postgres
default) we would fail the check for the existence of the constraint
since the names are truncated.
3. When checking for the presence of a constraint we assumed its type
would be `u` in `pg_constraint` because for us that means non FK
(i.e. not `f` type). That's incorrect since there are many more
types. Here we propose to handle `c,u,x` types.
For bullet 2 there is no simple way to ensure compliance of the name
length limit for constraints. We perform checks for table names in
standard code. There is no such alternative for constraints since their
names are enlarged by the table name, plus the `copy` method on
`ir.model.constraints` makes the name even longer. Hence we opt here to
check truncated names.
[IMP] code: improve uninstall tests
Perform extra checks for removal of SQL constraints. Note the test is
commented out in `__init__.py`. It can be uncommented locally for
testing. It's kept commented out to avoid random errors in runbot.
closes odoo/odoo#128050
Signed-off-by:
Raphael Collet <rco@odoo.com>
Showing
- odoo/addons/base/models/ir_model.py 9 additions, 5 deletionsodoo/addons/base/models/ir_model.py
- odoo/addons/base/tests/__init__.py 1 addition, 1 deletionodoo/addons/base/tests/__init__.py
- odoo/addons/base/tests/test_uninstall.py 22 additions, 0 deletionsodoo/addons/base/tests/test_uninstall.py
- odoo/addons/test_uninstall/models.py 10 additions, 0 deletionsodoo/addons/test_uninstall/models.py
- odoo/models.py 3 additions, 0 deletionsodoo/models.py
Loading