[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:
@@ -1751,13 +1751,9 @@ class IrModelConstraint(models.Model):
|
|||||||
'Constraints with the same name are unique per module.'),
|
'Constraints with the same name are unique per module.'),
|
||||||
]
|
]
|
||||||
|
|
||||||
def _module_data_uninstall(self):
|
def unlink(self):
|
||||||
"""
|
self.check_access_rights('unlink')
|
||||||
Delete PostgreSQL foreign keys and constraints tracked by this model.
|
self.check_access_rule('unlink')
|
||||||
"""
|
|
||||||
if not self.env.is_system():
|
|
||||||
raise AccessError(_('Administrator access is required to uninstall a module'))
|
|
||||||
|
|
||||||
ids_set = set(self.ids)
|
ids_set = set(self.ids)
|
||||||
for data in self.sorted(key='id', reverse=True):
|
for data in self.sorted(key='id', reverse=True):
|
||||||
name = tools.ustr(data.name)
|
name = tools.ustr(data.name)
|
||||||
@@ -1802,7 +1798,7 @@ class IrModelConstraint(models.Model):
|
|||||||
sql.Identifier(table), sql.Identifier(hname)))
|
sql.Identifier(table), sql.Identifier(hname)))
|
||||||
_logger.info('Dropped CONSTRAINT %s@%s', name, data.model.model)
|
_logger.info('Dropped CONSTRAINT %s@%s', name, data.model.model)
|
||||||
|
|
||||||
self.unlink()
|
return super().unlink()
|
||||||
|
|
||||||
def copy(self, default=None):
|
def copy(self, default=None):
|
||||||
default = dict(default or {})
|
default = dict(default or {})
|
||||||
@@ -2449,8 +2445,6 @@ class IrModelData(models.Model):
|
|||||||
modules._remove_copied_views()
|
modules._remove_copied_views()
|
||||||
|
|
||||||
# remove constraints
|
# 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)))
|
delete(self.env['ir.model.constraint'].browse(unique(constraint_ids)))
|
||||||
|
|
||||||
# If we delete a selection field, and some of its values have ondelete='cascade',
|
# If we delete a selection field, and some of its values have ondelete='cascade',
|
||||||
|
|||||||
Reference in New Issue
Block a user