From cb9b93b5c448980ec908a4de8aceea798ec5f0b1 Mon Sep 17 00:00:00 2001 From: Xavier-Do Date: Fri, 20 May 2022 11:23:47 +0000 Subject: [PATCH] [FIX] core: ordered to_compute MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Set order is not randomized for integers (integer hash is the integers itself and doesnt use pythonhashseed) but the output may be ordered or not depending of the values: In [2]: list(set(range(126,130))) Out[2]: [128, 129, 126, 127] In [3]: list(set(range(130,134))) Out[3]: [130, 131, 132, 133] This will lead to different results in query count tests depending on the current value of the sequence. The proposed solution is to use an Orderedset. We need to keep in mind that the initialisation/operation on Orderedset may be slower but this shouldn't represent any significant overhead in this case. closes odoo/odoo#91962 X-original-commit: da66b8fc008f97680584e266135b7fa7d3dedeca Signed-off-by: Rémy Voet --- odoo/api.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/odoo/api.py b/odoo/api.py index 584c141d14f..4ed88ec7e8f 100644 --- a/odoo/api.py +++ b/odoo/api.py @@ -26,7 +26,7 @@ from weakref import WeakSet from decorator import decorate from .exceptions import CacheMiss -from .tools import frozendict, classproperty, lazy_property, StackMap +from .tools import frozendict, classproperty, lazy_property, StackMap, OrderedSet from .tools.translate import _ _logger = logging.getLogger(__name__) @@ -821,7 +821,7 @@ class Transaction: # fields to protect {field: ids} self.protected = StackMap() # pending computations {field: ids} - self.tocompute = defaultdict(set) + self.tocompute = defaultdict(OrderedSet) # pending updates {model: {id: {field: value}}} self.towrite = defaultdict(lambda: defaultdict(dict))