From bc1f29e6c92c39670eeb82d98ca251f39079a9f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Mon, 10 Aug 2020 23:24:02 +0200 Subject: [PATCH] Use the ids order to fill cache with read data The shared cache is designed for loop usage so we must ensure that we fill the LRU dictionary in the same order as the loop will request attributes. So we must order the result of the read because the API does not return data in the same order as the list of ids. issue9518 review318041002 --- trytond/model/modelstorage.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/trytond/model/modelstorage.py b/trytond/model/modelstorage.py index 7f0f72aa93..f6cf34751f 100644 --- a/trytond/model/modelstorage.py +++ b/trytond/model/modelstorage.py @@ -1566,7 +1566,10 @@ class ModelStorage(Model): for i in ids if i in self._cache and name in self._cache[i]] else: - read_data = self.read(list(ids), list(ffields.keys())) + # Order data read to update cache in the same order + index = {i: n for n, i in enumerate(ids)} + read_data = self.read(list(index.keys()), list(ffields.keys())) + read_data.sort(key=lambda r: index[r['id']]) # create browse records for 'remote' models for data in read_data: id_ = data['id']