diff --git a/bin/addons/base/ir/ir_model.py b/bin/addons/base/ir/ir_model.py index aa89e0f71dd..c96044d2918 100644 --- a/bin/addons/base/ir/ir_model.py +++ b/bin/addons/base/ir/ir_model.py @@ -408,6 +408,9 @@ class ir_model_data(osv.osv): 'date_update': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'), 'noupdate': lambda *a: False } + _sql_constraints = [ + ('module_name_uniq', 'unique(name, module)', 'You can not have multiple records with the same id for the same module'), + ] def __init__(self, pool, cr): osv.osv.__init__(self, pool, cr) @@ -415,11 +418,13 @@ class ir_model_data(osv.osv): self.doinit = True self.unlink_mark = {} - def _get_id(self,cr, uid, module, xml_id): + @tools.cache() + def _get_id(self, cr, uid, module, xml_id): ids = self.search(cr, uid, [('module','=',module),('name','=', xml_id)]) - assert len(ids)==1, '%d reference(s) to %s.%s. You should have one and only one !' % (len(ids), module, xml_id) + if not ids: + raise Exception('No references to %s.%s' % (module, xml_id)) + # the sql constraints ensure us we have only one result return ids[0] - _get_id = tools.cache(skiparg=2)(_get_id) def _update_dummy(self,cr, uid, model, module, xml_id=False, store=True): if not xml_id: diff --git a/bin/tools/convert.py b/bin/tools/convert.py index fb85c4b88f2..220b272f4dd 100644 --- a/bin/tools/convert.py +++ b/bin/tools/convert.py @@ -256,7 +256,11 @@ form: module.record_id""" % (xml_id,) if len(d_search): ids = self.pool.get(d_model).search(cr,self.uid,eval(d_search)) if len(d_id): - ids.append(self.id_get(cr, d_model, d_id)) + try: + ids.append(self.id_get(cr, d_model, d_id)) + except: + # d_id cannot be found. doesn't matter in this case + pass if len(ids): self.pool.get(d_model).unlink(cr, self.uid, ids) self.pool.get('ir.model.data')._unlink(cr, self.uid, d_model, ids, direct=True)