[Zodb-checkins] SVN: ZODB/trunk/ Merge rev 27301 from 3.3 branch.

Tim Peters tim.one at comcast.net
Fri Aug 27 12:33:17 EDT 2004


Log message for revision 27302:
  Merge rev 27301 from 3.3 branch.
  
  Raise ConnectionStateError if an attempt to close a connection
  is made while the connection has a pending subtransaction.
  


Changed:
  U   ZODB/trunk/NEWS.txt
  U   ZODB/trunk/src/ZODB/Connection.py
  U   ZODB/trunk/src/ZODB/tests/testConnection.py


-=-
Modified: ZODB/trunk/NEWS.txt
===================================================================
--- ZODB/trunk/NEWS.txt	2004-08-27 16:29:40 UTC (rev 27301)
+++ ZODB/trunk/NEWS.txt	2004-08-27 16:33:17 UTC (rev 27302)
@@ -2,6 +2,20 @@
 =========================
 Release date: DD-MMM-YYYY
 
+Connection
+----------
+
+ZODB intends to raise ConnnectionStateError if an attempt is made to
+close a connection while modifications are pending (the connection is
+involved in a transaction that hasn't been abort()'ed or commit()'ed).
+It was missing the case where the only pending modifications were made
+in subtransactions.  This has been fixed.  If an attempt to close a
+connection with pending subtransactions is made now,
+
+    ConnnectionStateError: Cannot close a connection with a pending subtransaction
+
+is raised.
+
 transaction
 -----------
 

Modified: ZODB/trunk/src/ZODB/Connection.py
===================================================================
--- ZODB/trunk/src/ZODB/Connection.py	2004-08-27 16:29:40 UTC (rev 27301)
+++ ZODB/trunk/src/ZODB/Connection.py	2004-08-27 16:33:17 UTC (rev 27302)
@@ -541,6 +541,12 @@
             raise ConnectionStateError("Cannot close a connection joined to "
                                        "a transaction")
 
+        if self._tmp is not None:
+            # There are no direct modifications pending, but a subtransaction
+            # is pending.
+            raise ConnectionStateError("Cannot close a connection with a "
+                                       "pending subtransaction")
+
         if self._cache is not None:
             self._cache.incrgc() # This is a good time to do some GC
 

Modified: ZODB/trunk/src/ZODB/tests/testConnection.py
===================================================================
--- ZODB/trunk/src/ZODB/tests/testConnection.py	2004-08-27 16:29:40 UTC (rev 27301)
+++ ZODB/trunk/src/ZODB/tests/testConnection.py	2004-08-27 16:33:17 UTC (rev 27302)
@@ -264,7 +264,7 @@
         >>> transaction.commit()
         >>> cn.close()
 
-        Opening, making a change, committing, and aborting is fine.
+        Opening, making a change, and aborting is fine.
         >>> cn = db.open()
         >>> cn.root()['a'] = 1
         >>> transaction.abort()
@@ -272,7 +272,7 @@
 
         But trying to close with a change pending complains.
         >>> cn = db.open()
-        >>> cn.root()['a'] = 1
+        >>> cn.root()['a'] = 10
         >>> cn.close()
         Traceback (most recent call last):
           ...
@@ -281,7 +281,41 @@
         This leaves the connection as it was, so we can still commit
         the change.
         >>> transaction.commit()
+        >>> cn2 = db.open()
+        >>> cn2.root()['a']
+        10
+        >>> cn.close(); cn2.close()
+
+        Bug:  We weren't catching the case where the only changes pending
+        were in a subtransaction.
+        >>> cn = db.open()
+        >>> cn.root()['a'] = 100
+        >>> transaction.commit(True)
+        >>> cn.close()  # this was succeeding
+        Traceback (most recent call last):
+          ...
+        ConnectionStateError: Cannot close a connection with a pending subtransaction
+
+        Again this leaves the connection as it was.
+        >>> transaction.commit()
+        >>> cn2 = db.open()
+        >>> cn2.root()['a']
+        100
+        >>> cn.close(); cn2.close()
+
+        Make sure we can still close a connection after aborting a pending
+        subtransaction.
+        >>> cn = db.open()
+        >>> cn.root()['a'] = 1000
+        >>> transaction.commit(True)
+        >>> cn.root()['a']
+        1000
+        >>> transaction.abort()
+        >>> cn.root()['a']
+        100
         >>> cn.close()
+
+        >>> db.close()
         """
 
     def test_onCloseCallbacks(self):



More information about the Zodb-checkins mailing list