[FIX] ir.model: FK constraints for custom m2o fields were never created, creating possible data integrity errors

bzr revid: odo@openerp.com-20131010170718-lwoxkqc1tx7i8vhg
This commit is contained in:
Olivier Dony 2013-10-10 19:07:18 +02:00
parent 62b6c2b74b
commit dafa12d92c
2 changed files with 8 additions and 1 deletions

View File

@ -198,6 +198,7 @@ class ir_model(osv.osv):
select=vals.get('select_level', '0'), select=vals.get('select_level', '0'),
update_custom_fields=True) update_custom_fields=True)
self.pool.get(vals['model'])._auto_init(cr, ctx) self.pool.get(vals['model'])._auto_init(cr, ctx)
self.pool.get(vals['model'])._auto_end(cr, ctx) # actually create FKs!
openerp.modules.registry.RegistryManager.signal_registry_change(cr.dbname) openerp.modules.registry.RegistryManager.signal_registry_change(cr.dbname)
return res return res
@ -356,6 +357,7 @@ class ir_model_fields(osv.osv):
select=vals.get('select_level', '0'), select=vals.get('select_level', '0'),
update_custom_fields=True) update_custom_fields=True)
self.pool.get(vals['model'])._auto_init(cr, ctx) self.pool.get(vals['model'])._auto_init(cr, ctx)
self.pool.get(vals['model'])._auto_end(cr, ctx) # actually create FKs!
openerp.modules.registry.RegistryManager.signal_registry_change(cr.dbname) openerp.modules.registry.RegistryManager.signal_registry_change(cr.dbname)
return res return res
@ -473,6 +475,7 @@ class ir_model_fields(osv.osv):
for col_name, col_prop, val in patch_struct[1]: for col_name, col_prop, val in patch_struct[1]:
setattr(obj._columns[col_name], col_prop, val) setattr(obj._columns[col_name], col_prop, val)
obj._auto_init(cr, ctx) obj._auto_init(cr, ctx)
obj._auto_end(cr, ctx) # actually create FKs!
openerp.modules.registry.RegistryManager.signal_registry_change(cr.dbname) openerp.modules.registry.RegistryManager.signal_registry_change(cr.dbname)
return res return res

View File

@ -2847,8 +2847,12 @@ class BaseModel(object):
""" """
Record the creation of a constraint for this model, to make it possible Record the creation of a constraint for this model, to make it possible
to delete it later when the module is uninstalled. Type can be either to delete it later when the module is uninstalled. Type can be either
'f' or 'u' depending on the constraing being a foreign key or not. 'f' or 'u' depending on the constraint being a foreign key or not.
""" """
if not self._module:
# no need to save constraints for custom models as they're not part
# of any module
return
assert type in ('f', 'u') assert type in ('f', 'u')
cr.execute(""" cr.execute("""
SELECT 1 FROM ir_model_constraint, ir_module_module SELECT 1 FROM ir_model_constraint, ir_module_module