Commit ec836dfe authored by Jim Fulton's avatar Jim Fulton

Fixed a bug that caused savepoint rollback to not properly

set object state when objects implemented _p_invalidate methods
that reloaded ther state (unghostifiable objects).

https://bugs.launchpad.net/zodb/+bug/428039
parent 8e51c8a8
...@@ -1143,8 +1143,9 @@ class Connection(ExportImport, object): ...@@ -1143,8 +1143,9 @@ class Connection(ExportImport, object):
self._abort() self._abort()
self._registered_objects = [] self._registered_objects = []
src = self._storage src = self._storage
self._cache.invalidate(src.index) index = src.index
src.reset(*state) src.reset(*state)
self._cache.invalidate(index)
def _commit_savepoint(self, transaction): def _commit_savepoint(self, transaction):
"""Commit all changes made in savepoints and begin 2-phase commit """Commit all changes made in savepoints and begin 2-phase commit
......
...@@ -154,6 +154,34 @@ We simply rely on the underlying storage method. ...@@ -154,6 +154,34 @@ We simply rely on the underlying storage method.
False False
""" """
class SelfActivatingObject(persistent.Persistent):
def _p_invalidate(self):
super(SelfActivatingObject, self)._p_invalidate()
self._p_activate()
def testInvalidateAfterRollback():
"""\
The rollback used to invalidate objects before resetting the TmpStore.
This caused problems for custom _p_invalidate methods that would load
the wrong state.
>>> import ZODB.tests.util
>>> db = ZODB.tests.util.DB()
>>> connection = db.open()
>>> root = connection.root()
>>> root['p'] = p = SelfActivatingObject()
>>> transaction.commit()
>>> p.foo = 1
>>> sp = transaction.savepoint()
>>> p.foo = 2
>>> sp2 = transaction.savepoint()
>>> sp.rollback()
>>> p.foo # This used to wrongly return 2
1
"""
def tearDown(test): def tearDown(test):
transaction.abort() transaction.abort()
......
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