From 7ba32a9d66187ccc4984cbb2634603feea4eb23f Mon Sep 17 00:00:00 2001 From: Jason Madden Date: Tue, 18 Feb 2014 13:05:31 -0600 Subject: [PATCH] Fix traversal of the python picklecache ring when invalidating if the order doesn't exactly match the ring --- persistent/picklecache.py | 3 ++- persistent/tests/test_picklecache.py | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/persistent/picklecache.py b/persistent/picklecache.py index 7562261..6b2d331 100644 --- a/persistent/picklecache.py +++ b/persistent/picklecache.py @@ -122,7 +122,7 @@ def mru(self, oid): # splice into new self.ring.prev.next, node.prev = node, self.ring.prev self.ring.prev, node.next = node, self.ring - + def ringlen(self): """ See IPickleCache. """ @@ -257,5 +257,6 @@ def _invalidate(self, oid): if node.object is value: node.prev.next, node.next.prev = node.next, node.prev break + node = node.next elif oid in self.persistent_classes: del self.persistent_classes[oid] diff --git a/persistent/tests/test_picklecache.py b/persistent/tests/test_picklecache.py index af15dde..82c8db8 100644 --- a/persistent/tests/test_picklecache.py +++ b/persistent/tests/test_picklecache.py @@ -661,6 +661,25 @@ def test_invalidate_hit_multiple_mixed(self): self.assertEqual(c1._p_state, GHOST) self.assertEqual(c2._p_state, GHOST) + def test_invalidate_hit_multiple_non_ghost(self): + from persistent.interfaces import UPTODATE + from persistent.interfaces import GHOST + from persistent._compat import _b + KEY = _b('123') + KEY2 = _b('456') + cache = self._makeOne() + c1 = self._makePersist(oid=KEY, jar=cache.jar, state=UPTODATE) + cache[KEY] = c1 + c2 = self._makePersist(oid=KEY2, jar=cache.jar, state=UPTODATE) + cache[KEY2] = c2 + self.assertEqual(cache.ringlen(), 2) + # These should be in the opposite order of how they were + # added to the ring to ensure ring traversal works + cache.invalidate([KEY2, KEY]) + self.assertEqual(cache.ringlen(), 0) + self.assertEqual(c1._p_state, GHOST) + self.assertEqual(c2._p_state, GHOST) + def test_invalidate_hit_pclass(self): from persistent._compat import _b KEY = _b('123')