Commit 3975334c authored by Jason Madden's avatar Jason Madden

KeyError would be raised during ZODB serialization; catch that. Not sure if...

KeyError would be raised during ZODB serialization; catch that. Not sure if this is the best solution or not but it gets zope.container passing.
parent 690441d9
......@@ -390,8 +390,16 @@ class Persistent(object):
# detail, the '_cache' attribute of the jar. We made it a
# private API to avoid the cycle of keeping a reference to
# the cache on the persistent object.
if self.__jar is not None and self.__oid is not None:
self.__jar._cache.mru(self.__oid)
if self.__jar is not None and self.__oid is not None and self._p_state >= 0:
# This scenario arises in ZODB: ZODB.serialize.ObjectWriter
# can assign a jar and an oid to newly seen persistent objects,
# but because they are newly created, they aren't in the
# pickle cache yet. There doesn't seem to be a way to distinguish
# that at this level, all we can do is catch it
try:
self.__jar._cache.mru(self.__oid)
except KeyError:
pass
def _estimated_size_in_24_bits(value):
......
......@@ -1319,7 +1319,29 @@ class PyPersistentTests(unittest.TestCase, _Persistent_Base):
def _clearMRU(self, jar):
jar._cache._mru[:] = []
def test_accessed_with_jar_and_oid_but_not_in_cache(self):
# This scenario arises in ZODB: ZODB.serialize.ObjectWriter
# can assign a jar and an oid to newly seen persistent objects,
# but because they are newly created, they aren't in the
# pickle cache yet.
# Nothing should blow up when this happens
from persistent._compat import _b
KEY = _b('123')
jar = self._makeJar()
c1 = self._makeOne()
c1._p_oid = KEY
c1._p_jar = jar
orig_mru = jar._cache.mru
def mru(oid):
# Mimic what the real cache does
if oid not in jar._cache._mru:
raise KeyError(oid)
orig_mru(oid)
jar._cache.mru = mru
c1._p_accessed()
self._checkMRU(jar, [])
_add_to_suite = [PyPersistentTests]
if not os.environ.get('PURE_PYTHON'):
......@@ -1336,7 +1358,7 @@ if not os.environ.get('PURE_PYTHON'):
def _checkMRU(self, jar, value):
pass # Figure this out later
def _clearMRU(self, jar):
pass # Figure this out later
......
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