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)