Skip to content

Commit

Permalink
Resolve merge conflict.
Browse files Browse the repository at this point in the history
  • Loading branch information
tseaver committed Feb 19, 2014
2 parents 59310ca + 3975334 commit a5f98fe
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
12 changes: 10 additions & 2 deletions persistent/persistence.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,16 @@ def _p_accessed(self):
# 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):
Expand Down
22 changes: 22 additions & 0 deletions persistent/tests/test_persistence.py
Original file line number Diff line number Diff line change
Expand Up @@ -1328,6 +1328,28 @@ def _checkMRU(self, jar, value):
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'):
Expand Down

0 comments on commit a5f98fe

Please sign in to comment.