uninstall: avoid errors during uninstall
When uninstalling a module, remove the ir.model.constraint after removing the non-model records and before fields and model definition. Without this fix, some constraint would be removed too early allowing to have broken relations and data left from removed module.
This commit is contained in:
parent
25292ef0a5
commit
426993e06d
|
@ -1087,13 +1087,20 @@ class ir_model_data(osv.osv):
|
||||||
|
|
||||||
# Remove non-model records first, then model fields, and finish with models
|
# Remove non-model records first, then model fields, and finish with models
|
||||||
unlink_if_refcount((model, res_id) for model, res_id in to_unlink
|
unlink_if_refcount((model, res_id) for model, res_id in to_unlink
|
||||||
if model not in ('ir.model','ir.model.fields'))
|
if model not in ('ir.model','ir.model.fields','ir.model.constraint'))
|
||||||
|
unlink_if_refcount((model, res_id) for model, res_id in to_unlink
|
||||||
|
if model == 'ir.model.constraint')
|
||||||
|
|
||||||
|
ir_module_module = self.pool['ir.module.module']
|
||||||
|
ir_model_constraint = self.pool['ir.model.constraint']
|
||||||
|
modules_to_remove_ids = ir_module_module.search(cr, uid, [('name', 'in', modules_to_remove)], context=context)
|
||||||
|
constraint_ids = ir_model_constraint.search(cr, uid, [('module', 'in', modules_to_remove_ids)], context=context)
|
||||||
|
ir_model_constraint._module_data_uninstall(cr, uid, constraint_ids, context)
|
||||||
|
|
||||||
unlink_if_refcount((model, res_id) for model, res_id in to_unlink
|
unlink_if_refcount((model, res_id) for model, res_id in to_unlink
|
||||||
if model == 'ir.model.fields')
|
if model == 'ir.model.fields')
|
||||||
|
|
||||||
ir_model_relation = self.pool.get('ir.model.relation')
|
ir_model_relation = self.pool.get('ir.model.relation')
|
||||||
ir_module_module = self.pool.get('ir.module.module')
|
|
||||||
modules_to_remove_ids = ir_module_module.search(cr, uid, [('name', 'in', modules_to_remove)])
|
|
||||||
relation_ids = ir_model_relation.search(cr, uid, [('module', 'in', modules_to_remove_ids)])
|
relation_ids = ir_model_relation.search(cr, uid, [('module', 'in', modules_to_remove_ids)])
|
||||||
ir_model_relation._module_data_uninstall(cr, uid, relation_ids, context)
|
ir_model_relation._module_data_uninstall(cr, uid, relation_ids, context)
|
||||||
|
|
||||||
|
|
|
@ -434,11 +434,7 @@ class module(osv.osv):
|
||||||
including the deletion of all database structures created by the module:
|
including the deletion of all database structures created by the module:
|
||||||
tables, columns, constraints, etc."""
|
tables, columns, constraints, etc."""
|
||||||
ir_model_data = self.pool.get('ir.model.data')
|
ir_model_data = self.pool.get('ir.model.data')
|
||||||
ir_model_constraint = self.pool.get('ir.model.constraint')
|
|
||||||
modules_to_remove = [m.name for m in self.browse(cr, uid, ids, context)]
|
modules_to_remove = [m.name for m in self.browse(cr, uid, ids, context)]
|
||||||
modules_to_remove_ids = [m.id for m in self.browse(cr, uid, ids, context)]
|
|
||||||
constraint_ids = ir_model_constraint.search(cr, uid, [('module', 'in', modules_to_remove_ids)])
|
|
||||||
ir_model_constraint._module_data_uninstall(cr, uid, constraint_ids, context)
|
|
||||||
ir_model_data._module_data_uninstall(cr, uid, modules_to_remove, context)
|
ir_model_data._module_data_uninstall(cr, uid, modules_to_remove, context)
|
||||||
self.write(cr, uid, ids, {'state': 'uninstalled'})
|
self.write(cr, uid, ids, {'state': 'uninstalled'})
|
||||||
return True
|
return True
|
||||||
|
|
Loading…
Reference in New Issue