[Zodb-checkins] SVN: ZODB/branches/3.4/src/ZODB/ Fixed a bug that caused assertion errors if an object was added in a

Jim Fulton jim at zope.com
Sat Apr 23 23:02:00 EDT 2005


Log message for revision 30130:
  Fixed a bug that caused assertion errors if an object was added in a
  savepoint, then modified and then aborted.
  
  Also added missing code to clear registered objects when a savepoint
  was rolled back.
  

Changed:
  U   ZODB/branches/3.4/src/ZODB/Connection.py
  U   ZODB/branches/3.4/src/ZODB/tests/testConnectionSavepoint.py

-=-
Modified: ZODB/branches/3.4/src/ZODB/Connection.py
===================================================================
--- ZODB/branches/3.4/src/ZODB/Connection.py	2005-04-24 01:29:02 UTC (rev 30129)
+++ ZODB/branches/3.4/src/ZODB/Connection.py	2005-04-24 03:02:00 UTC (rev 30130)
@@ -325,11 +325,19 @@
     def abort(self, transaction):
         """Abort a transaction and forget all changes."""
 
+        # The order is important here.  We want to abort registered
+        # objects before we process the cache.  Otherwise, we may un-add
+        # objects added in savepoints.  If they've been modified since
+        # the savepoint, then they won't have _p_oid or _p_jar after
+        # they've been unadded. This will make the code in _abort
+        # confused.
+        
+
+        self._abort()
+
         if self._savepoint_storage is not None:
             self._abort_savepoint()
 
-        self._abort()
-
         self._tpc_cleanup()
 
     def _abort(self):
@@ -988,6 +996,7 @@
 
     def _rollback(self, state):
         self._abort()
+        self._registered_objects = []
         src = self._storage
         self._cache.invalidate(src.index)
         src.reset(*state)

Modified: ZODB/branches/3.4/src/ZODB/tests/testConnectionSavepoint.py
===================================================================
--- ZODB/branches/3.4/src/ZODB/tests/testConnectionSavepoint.py	2005-04-24 01:29:02 UTC (rev 30129)
+++ ZODB/branches/3.4/src/ZODB/tests/testConnectionSavepoint.py	2005-04-24 03:02:00 UTC (rev 30130)
@@ -17,11 +17,26 @@
 """
 import unittest
 from zope.testing import doctest
+import persistent.dict, transaction
 
+def testAddingThenModifyThenAbort():
+    """
+    >>> import ZODB.tests.util
+    >>> db = ZODB.tests.util.DB()
+    >>> connection = db.open()
+    >>> root = connection.root()
 
+    >>> ob = persistent.dict.PersistentDict()
+    >>> root['ob'] = ob
+    >>> sp = transaction.savepoint()
+    >>> ob.x = 1
+    >>> transaction.abort()
+  
+"""
 def test_suite():
     return unittest.TestSuite((
         doctest.DocFileSuite('testConnectionSavepoint.txt'),
+        doctest.DocTestSuite(),
         ))
 
 if __name__ == '__main__':



More information about the Zodb-checkins mailing list