Commit a5f98fe6 authored by Tres Seaver's avatar Tres Seaver

Resolve merge conflict.

parents 59310ca3 3975334c
......@@ -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):
......
......@@ -1328,6 +1328,28 @@ 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'):
......
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