From 576b6265a6bb89dc63fc21b4e0f6b6c5077b437b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Thu, 8 Oct 2020 21:26:20 +0200 Subject: [PATCH] Update ModelSingleton to use the custom cache class API issue9641 review292321003 --- trytond/model/modelsingleton.py | 4 +--- trytond/tests/test_modelsingleton.py | 4 ++++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/trytond/model/modelsingleton.py b/trytond/model/modelsingleton.py index 404da4b511..5476146772 100644 --- a/trytond/model/modelsingleton.py +++ b/trytond/model/modelsingleton.py @@ -61,9 +61,7 @@ class ModelSingleton(ModelStorage): super(ModelSingleton, cls).write(*args) # Clean local cache of original records for record in sum(actions[0:None:2], []): - local_cache = record._local_cache.get(record.id) - if local_cache: - local_cache.clear() + record._local_cache.pop(record.id, None) # Clean transaction cache of all ids for cache in Transaction().cache.values(): if cls.__name__ in cache: diff --git a/trytond/tests/test_modelsingleton.py b/trytond/tests/test_modelsingleton.py index 596ce485a9..f932ba197c 100644 --- a/trytond/tests/test_modelsingleton.py +++ b/trytond/tests/test_modelsingleton.py @@ -136,6 +136,7 @@ class ModelSingletonTestCase(unittest.TestCase): Singleton = pool.get('test.singleton') singleton, = Singleton.create([{'name': 'foo'}]) + singleton.name # Fill the cache singleton2 = Singleton(singleton.id + 1) # Use a different id singleton2.name # Fill the cache Singleton.write([singleton], {'name': 'bar'}) @@ -143,6 +144,9 @@ class ModelSingletonTestCase(unittest.TestCase): self.assertEqual(singleton2.name, 'bar') + Singleton.delete([singleton]) + self.assertEqual(singleton2.name, 'test') + def suite(): return unittest.TestLoader().loadTestsFromTestCase(ModelSingletonTestCase)