changeset 9d14839ecb46 in trytond:default
details: https://hg.tryton.org/trytond?cmd=changeset;node=9d14839ecb46
description:
Update ModelSingleton to use the custom cache class API
issue9641
review292321003
diffstat:
trytond/model/modelsingleton.py | 4 +---
trytond/tests/test_modelsingleton.py | 4 ++++
2 files changed, 5 insertions(+), 3 deletions(-)
diffs (35 lines):
diff -r da4aa730aba2 -r 9d14839ecb46 trytond/model/modelsingleton.py
--- a/trytond/model/modelsingleton.py Sun Oct 04 23:04:01 2020 +0200
+++ b/trytond/model/modelsingleton.py Thu Oct 08 21:26:20 2020 +0200
@@ -61,9 +61,7 @@
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 -r da4aa730aba2 -r 9d14839ecb46 trytond/tests/test_modelsingleton.py
--- a/trytond/tests/test_modelsingleton.py Sun Oct 04 23:04:01 2020 +0200
+++ b/trytond/tests/test_modelsingleton.py Thu Oct 08 21:26:20 2020 +0200
@@ -136,6 +136,7 @@
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 @@
self.assertEqual(singleton2.name, 'bar')
+ Singleton.delete([singleton])
+ self.assertEqual(singleton2.name, 'test')
+
def suite():
return unittest.TestLoader().loadTestsFromTestCase(ModelSingletonTestCase)