[FIX] core: remove SQL constraints upon ir.model.constraint removal

Otherwise we leave the constraints in the table. Common source of
upgrade issues.

closes odoo/odoo#163623

X-original-commit: 847a24e6f7f57c755cf6f42597b1ac75908f2c83
Signed-off-by: Raphael Collet <rco@odoo.com>
Signed-off-by: Alvaro Fuentes Suarez (afu) <afu@odoo.com>
This commit is contained in:
Alvaro Fuentes
2024-04-29 08:07:30 +00:00
parent fc16ecced2
commit 1bc016fa0f
+4 -10
View File
@@ -1751,13 +1751,9 @@ class IrModelConstraint(models.Model):
'Constraints with the same name are unique per module.'),
]
def _module_data_uninstall(self):
"""
Delete PostgreSQL foreign keys and constraints tracked by this model.
"""
if not self.env.is_system():
raise AccessError(_('Administrator access is required to uninstall a module'))
def unlink(self):
self.check_access_rights('unlink')
self.check_access_rule('unlink')
ids_set = set(self.ids)
for data in self.sorted(key='id', reverse=True):
name = tools.ustr(data.name)
@@ -1802,7 +1798,7 @@ class IrModelConstraint(models.Model):
sql.Identifier(table), sql.Identifier(hname)))
_logger.info('Dropped CONSTRAINT %s@%s', name, data.model.model)
self.unlink()
return super().unlink()
def copy(self, default=None):
default = dict(default or {})
@@ -2449,8 +2445,6 @@ class IrModelData(models.Model):
modules._remove_copied_views()
# remove constraints
constraints = self.env['ir.model.constraint'].search([('module', 'in', modules.ids)])
constraints._module_data_uninstall()
delete(self.env['ir.model.constraint'].browse(unique(constraint_ids)))
# If we delete a selection field, and some of its values have ondelete='cascade',