Skip to content

Commit

Permalink
new_ghost doesn't clear object state, preserving __getnewargs__ values.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamadden committed Dec 19, 2016
1 parent ff64867 commit 930088a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
32 changes: 17 additions & 15 deletions persistent/persistence.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,27 +413,29 @@ def _p_invalidate(self):
_OSA(self, '_Persistent__flags', 0)
self._p_deactivate()

def _p_invalidate_deactivate_helper(self):
def _p_invalidate_deactivate_helper(self, clear=True):
jar = _OGA(self, '_Persistent__jar')
if jar is None:
return

if _OGA(self, '_Persistent__flags') is not None:
_OSA(self, '_Persistent__flags', None)
idict = getattr(self, '__dict__', None)
if idict is not None:
idict.clear()
type_ = type(self)
# ( for backward-compatibility reason we release __slots__ only if
# class does not override __new__ )
if type_.__new__ is Persistent.__new__:
for slotname in Persistent._slotnames(self, _v_exclude=False):
try:
getattr(type_, slotname).__delete__(self)
except AttributeError:
# AttributeError means slot variable was not initialized at all -
# - we can simply skip its deletion.
pass

if clear:
idict = _OGA(self, '__dict__', None)
if idict is not None:
idict.clear()
type_ = type(self)
# for backward-compatibility reason we release __slots__ only if
# class does not override __new__
if type_.__new__ is Persistent.__new__:
for slotname in Persistent._slotnames(self, _v_exclude=False):
try:
getattr(type_, slotname).__delete__(self)
except AttributeError:
# AttributeError means slot variable was not initialized at all -
# - we can simply skip its deletion.
pass

# Implementation detail: deactivating/invalidating
# updates the size of the cache (if we have one)
Expand Down
2 changes: 1 addition & 1 deletion persistent/picklecache.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def new_ghost(self, oid, obj):
# careful to avoid broken _p_invalidate and _p_deactivate
# that don't call the super class. See ZODB's
# testConnection.doctest_proper_ghost_initialization_with_empty__p_deactivate
obj._p_invalidate_deactivate_helper()
obj._p_invalidate_deactivate_helper(False)
self[oid] = obj

def reify(self, to_reify):
Expand Down

0 comments on commit 930088a

Please sign in to comment.