[Zope3-checkins] CVS: ZODB/src/ZODB - Connection.py:1.152

Jeremy Hylton jeremy at zope.com
Fri Apr 16 15:55:36 EDT 2004


Update of /cvs-repository/ZODB/src/ZODB
In directory cvs.zope.org:/tmp/cvs-serv25453/src/ZODB

Modified Files:
	Connection.py 
Log Message:
Variant of a patch from Gintautas Miliauskas.

The old code used itertools.chain(), which didn't work as expected.
If the first of the two iterator grew after the chain had started
consuming the second iterator, the new element(s) in the first
iterator would never be consumed.  

Fix this bug by eliminating the need for chaining.  Process all the
_added_during_commit objects at the end, each with its own
ObjectWriter instance.


=== ZODB/src/ZODB/Connection.py 1.151 => 1.152 ===
--- ZODB/src/ZODB/Connection.py:1.151	Fri Apr 16 15:07:00 2004
+++ ZODB/src/ZODB/Connection.py	Fri Apr 16 15:55:04 2004
@@ -18,7 +18,6 @@
 import logging
 import sys
 import threading
-import itertools
 import warnings
 from time import time
 from utils import u64
@@ -568,6 +567,14 @@
             self._importDuringCommit(transaction, *self._import)
             self._import = None
 
+        # Just in case an object is added as a side-effect of storing
+        # a modified object.  If, for example, a __getstate__() method
+        # calls add(), the newly added objects will show up in
+        # _added_during_commit.  This sounds insane, but has actually
+        # happened.
+        
+        self._added_during_commit = []
+        
         for obj in self._registered_objects:
             oid = obj._p_oid
             assert oid
@@ -592,9 +599,12 @@
 
             self._store_objects(ObjectWriter(obj), transaction)
 
+        for obj in self._added_during_commit:
+            self._storage_objects(ObjectWriter(obj), transaction)
+        self._added_during_commit = None
+
     def _store_objects(self, writer, transaction):
-        self._added_during_commit = []
-        for obj in itertools.chain(writer, self._added_during_commit):
+        for obj in writer:
             oid = obj._p_oid
             serial = getattr(obj, "_p_serial", z64)
 
@@ -625,7 +635,6 @@
                     raise
 
             self._handle_serial(s, oid)
-        self._added_during_commit = None
 
     def commit_sub(self, t):
         """Commit all work done in all subtransactions for this transaction."""




More information about the Zope3-Checkins mailing list