Update ModelSingleton to use the custom cache class API
issue9641 review292321003
This commit is contained in:
1 parent
97194bc10b
commit
576b6265a6
2 files changed
+5
-3
No files matched your search
@@ -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:
|
||||
|
||||
@@ -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)
|
||||
Reference in new issue
Block a user