[Zodb-checkins] SVN: ZODB/branches/3.3/ Raise ConnectionStateError if an attempt to close a connection

Tim Peters tim.one at comcast.net
Fri Aug 27 12:29:40 EDT 2004


Log message for revision 27301:
  Raise ConnectionStateError if an attempt to close a connection
  is made while the connection has a pending subtransaction.
  


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


-=-
Modified: ZODB/branches/3.3/NEWS.txt
===================================================================
--- ZODB/branches/3.3/NEWS.txt	2004-08-27 16:24:30 UTC (rev 27300)
+++ ZODB/branches/3.3/NEWS.txt	2004-08-27 16:29:40 UTC (rev 27301)
@@ -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/branches/3.3/src/ZODB/Connection.py
===================================================================
--- ZODB/branches/3.3/src/ZODB/Connection.py	2004-08-27 16:24:30 UTC (rev 27300)
+++ ZODB/branches/3.3/src/ZODB/Connection.py	2004-08-27 16:29:40 UTC (rev 27301)
@@ -540,6 +540,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/branches/3.3/src/ZODB/tests/testConnection.py
===================================================================
--- ZODB/branches/3.3/src/ZODB/tests/testConnection.py	2004-08-27 16:24:30 UTC (rev 27300)
+++ ZODB/branches/3.3/src/ZODB/tests/testConnection.py	2004-08-27 16:29:40 UTC (rev 27301)
@@ -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