From 03708af20e389ce6c4a63283929ea2d95d420e1c Mon Sep 17 00:00:00 2001 From: Xavier-Do Date: Tue, 10 Mar 2020 11:49:43 +0000 Subject: [PATCH] [IMP] core: make exists determinist When testing odoo, errors can occur an undeterministic way, wich can lead to strange and unreproductible behaviour. This also means that the performance can change from one execution to another, making it quite difficult to track performance variation on a global scope. This commit makes the result of `exists()` deterministic in terms of order. The side effect is to keep record ids in the same order as the original recordset, which may be useful. closes odoo/odoo#47282 Signed-off-by: Raphael Collet (rco) Co-authored-by: Raphael Collet --- odoo/models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/odoo/models.py b/odoo/models.py index a5d8ddb7900..9ca62161f2b 100644 --- a/odoo/models.py +++ b/odoo/models.py @@ -4611,8 +4611,8 @@ Record ids: %(records)s return self query = """SELECT id FROM "%s" WHERE id IN %%s""" % self._table self._cr.execute(query, [tuple(ids)]) - ids = [r[0] for r in self._cr.fetchall()] - return self.browse(ids + new_ids) + valid_ids = set([r[0] for r in self._cr.fetchall()] + new_ids) + return self.browse(i for i in self._ids if i in valid_ids) def _check_recursion(self, parent=None): """