Commit da104183 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

once key is deleted, get(key) should raises KeyError even in the same transaction.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@39559 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 01c8e3a9
...@@ -168,6 +168,8 @@ if memcache is not None: ...@@ -168,6 +168,8 @@ if memcache is not None:
# We need to register in this function too to be able to flush cache at # We need to register in this function too to be able to flush cache at
# transaction end. # transaction end.
self._register() self._register()
if self.scheduled_action_dict.get(key) == DELETE_ACTION:
raise KeyError
encoded_key = encodeKey(key) encoded_key = encodeKey(key)
result = self.local_cache.get(key, MARKER) result = self.local_cache.get(key, MARKER)
if result is MARKER: if result is MARKER:
...@@ -207,8 +209,6 @@ if memcache is not None: ...@@ -207,8 +209,6 @@ if memcache is not None:
def get(self, key, default=None): def get(self, key, default=None):
""" """
Get an item from local cache, otherwise from memcached. Get an item from local cache, otherwise from memcached.
Note that because __getitem__ never raises error, 'default' will never
be used (None will be returned instead).
""" """
try: try:
return self.__getitem__(key) return self.__getitem__(key)
......
...@@ -154,8 +154,6 @@ class TestMemcachedTool(ERP5TypeTestCase): ...@@ -154,8 +154,6 @@ class TestMemcachedTool(ERP5TypeTestCase):
def test_04_deleteValue(self): def test_04_deleteValue(self):
""" """
Tests that deleting a value works. Tests that deleting a value works.
Note that deleting a value should raise a KeyError.
But because of python-memcached limitations, all we get is a None value.
""" """
tested_dict = self.getMemcachedDict() tested_dict = self.getMemcachedDict()
tested_key = 'test_key' tested_key = 'test_key'
...@@ -163,7 +161,7 @@ class TestMemcachedTool(ERP5TypeTestCase): ...@@ -163,7 +161,7 @@ class TestMemcachedTool(ERP5TypeTestCase):
tested_dict[tested_key] = tested_value tested_dict[tested_key] = tested_value
self.assertTrue(tested_dict[tested_key] == tested_value) self.assertTrue(tested_dict[tested_key] == tested_value)
del tested_dict[tested_key] del tested_dict[tested_key]
self.assertTrue(tested_dict[tested_key] is None) self.assertRaises(KeyError, tested_dict.__getitem__, tested_key)
def test_05_deleteValueAndCommit(self): def test_05_deleteValueAndCommit(self):
""" """
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment