Commit 930088ad authored by Jason Madden's avatar Jason Madden

new_ghost doesn't clear object state, preserving __getnewargs__ values.

parent ff64867c
...@@ -413,27 +413,29 @@ class Persistent(object): ...@@ -413,27 +413,29 @@ class Persistent(object):
_OSA(self, '_Persistent__flags', 0) _OSA(self, '_Persistent__flags', 0)
self._p_deactivate() self._p_deactivate()
def _p_invalidate_deactivate_helper(self): def _p_invalidate_deactivate_helper(self, clear=True):
jar = _OGA(self, '_Persistent__jar') jar = _OGA(self, '_Persistent__jar')
if jar is None: if jar is None:
return return
if _OGA(self, '_Persistent__flags') is not None: if _OGA(self, '_Persistent__flags') is not None:
_OSA(self, '_Persistent__flags', None) _OSA(self, '_Persistent__flags', None)
idict = getattr(self, '__dict__', None)
if idict is not None: if clear:
idict.clear() idict = _OGA(self, '__dict__', None)
type_ = type(self) if idict is not None:
# ( for backward-compatibility reason we release __slots__ only if idict.clear()
# class does not override __new__ ) type_ = type(self)
if type_.__new__ is Persistent.__new__: # for backward-compatibility reason we release __slots__ only if
for slotname in Persistent._slotnames(self, _v_exclude=False): # class does not override __new__
try: if type_.__new__ is Persistent.__new__:
getattr(type_, slotname).__delete__(self) for slotname in Persistent._slotnames(self, _v_exclude=False):
except AttributeError: try:
# AttributeError means slot variable was not initialized at all - getattr(type_, slotname).__delete__(self)
# - we can simply skip its deletion. except AttributeError:
pass # AttributeError means slot variable was not initialized at all -
# - we can simply skip its deletion.
pass
# Implementation detail: deactivating/invalidating # Implementation detail: deactivating/invalidating
# updates the size of the cache (if we have one) # updates the size of the cache (if we have one)
......
...@@ -246,7 +246,7 @@ class PickleCache(object): ...@@ -246,7 +246,7 @@ class PickleCache(object):
# careful to avoid broken _p_invalidate and _p_deactivate # careful to avoid broken _p_invalidate and _p_deactivate
# that don't call the super class. See ZODB's # that don't call the super class. See ZODB's
# testConnection.doctest_proper_ghost_initialization_with_empty__p_deactivate # testConnection.doctest_proper_ghost_initialization_with_empty__p_deactivate
obj._p_invalidate_deactivate_helper() obj._p_invalidate_deactivate_helper(False)
self[oid] = obj self[oid] = obj
def reify(self, to_reify): def reify(self, to_reify):
......
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