From e6716791836e0441217fc51aeb8ac1acccf0b2f4 Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Tue, 26 Sep 2017 10:52:43 +0200 Subject: [PATCH] [FIX] fields: do not use int() to retrieve record id When reading a one2many field, the inverse field of the retrieved lines may already be assigned in cache to a new record. This can happen during an onchange. In that case, the algorithm crashes. Let's clean it up! --- odoo/fields.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/odoo/fields.py b/odoo/fields.py index 437b349a9a6..780a1c318bc 100644 --- a/odoo/fields.py +++ b/odoo/fields.py @@ -2192,6 +2192,7 @@ class One2many(_RelationalMulti): # retrieve the lines in the comodel comodel = records.env[self.comodel_name].with_context(**self.context) inverse = self.inverse_name + get_id = (lambda rec: rec.id) if comodel._fields[inverse].type == 'many2one' else int domain = self.domain(records) if callable(self.domain) else self.domain domain = domain + [(inverse, 'in', records.ids)] lines = comodel.search(domain, limit=self.limit) @@ -2200,7 +2201,7 @@ class One2many(_RelationalMulti): group = defaultdict(list) for line in lines.with_context(prefetch_fields=False): # line[inverse] may be a record or an integer - group[int(line[inverse])].append(line.id) + group[get_id(line[inverse])].append(line.id) # store result in cache cache = records.env.cache