From 16a0b3b24979838ceaa449320289cd957d3fdc65 Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Thu, 22 Sep 2016 12:29:24 +0200 Subject: [PATCH] [FIX] models: do not delete `ir.model.fields` in `_field_create` (#13565) Following 5c5d0865b9248cf01a125240704d2c6b49d1a125, apparently unused records are simply deleted after updating existing ones. This causes an issue when a module is installed or upgraded. The inspection of `ir.model.fields` records is based on a *partial* registry (not all modules loaded); therefore records will be deleted and recreated afterwards. This triggers inconsistencies in other models that refer to `ir.model.fields`, like server actions, base action rules, mail templates, etc.: many2one fields will be set to null! --- openerp/models.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/openerp/models.py b/openerp/models.py index 8317039705c..2b94a3bff5f 100644 --- a/openerp/models.py +++ b/openerp/models.py @@ -443,7 +443,7 @@ class BaseModel(object): raise UserError(_("Serialization field `%s` not found for sparse field `%s`!") % (f.serialization_field, k)) vals['serialization_field_id'] = serialization_field_id[0] - col = cols.pop(k, None) + col = cols.get(k) if not col: cr.execute('select nextval(%s)', ('ir_model_fields_id_seq',)) id = cr.fetchone()[0] @@ -472,11 +472,6 @@ class BaseModel(object): cr.execute(query, vals) break - # remove ir_model_fields that should not be there - if cols: - ids = tuple(col['id'] for col in cols.itervalues()) - cr.execute("DELETE FROM ir_model_fields WHERE id IN %s", (ids,)) - self.invalidate_cache(cr, SUPERUSER_ID) @api.model