[Zodb-checkins] SVN: ZODB/branches/3.8/src/ZODB/ don't fail when trying to invalidate blobs for which readers and writers

Rob Miller ra at burningman.com
Thu Sep 11 15:15:13 EDT 2008


Log message for revision 91064:
  don't fail when trying to invalidate blobs for which readers and writers
  have not been initialized (as can happen when doing a deep copy of a
  blob object)
  

Changed:
  U   ZODB/branches/3.8/src/ZODB/blob.py
  U   ZODB/branches/3.8/src/ZODB/tests/testblob.py

-=-
Modified: ZODB/branches/3.8/src/ZODB/blob.py
===================================================================
--- ZODB/branches/3.8/src/ZODB/blob.py	2008-09-11 18:18:58 UTC (rev 91063)
+++ ZODB/branches/3.8/src/ZODB/blob.py	2008-09-11 19:15:13 UTC (rev 91064)
@@ -93,7 +93,7 @@
         # XXX should we warn of this? Maybe?
         if self._p_changed is None:
             return
-        for ref in self.readers+self.writers:
+        for ref in (self.readers or [])+(self.writers or []):
             f = ref()
             if f is not None:
                 f.close()

Modified: ZODB/branches/3.8/src/ZODB/tests/testblob.py
===================================================================
--- ZODB/branches/3.8/src/ZODB/tests/testblob.py	2008-09-11 18:18:58 UTC (rev 91063)
+++ ZODB/branches/3.8/src/ZODB/tests/testblob.py	2008-09-11 19:15:13 UTC (rev 91064)
@@ -17,6 +17,10 @@
 from zope.testing import doctest, renormalizing
 import ZODB.tests.util
 
+from StringIO import StringIO
+from pickle import Pickler
+from pickle import Unpickler
+
 from ZODB import utils
 from ZODB.FileStorage import FileStorage
 from ZODB.blob import Blob, BlobStorage
@@ -98,7 +102,7 @@
                           """)
 
 
-class BlobUndoTests(unittest.TestCase):
+class BlobTests(unittest.TestCase):
 
     def setUp(self):
         self.test_dir = tempfile.mkdtemp()
@@ -111,6 +115,34 @@
         os.chdir(self.here)
         ZODB.blob.remove_committed_dir(self.test_dir)
 
+class BlobCloneTests(BlobTests):
+
+    def testDeepCopyCanInvalidate(self):
+        """
+        Tests regression for invalidation problems related to missing
+        readers and writers values in cloned objects (see
+        http://mail.zope.org/pipermail/zodb-dev/2008-August/012054.html)
+        """
+        base_storage = FileStorage(self.storagefile)
+        blob_storage = BlobStorage(self.blob_dir, base_storage)
+        database = DB(blob_storage)
+        connection = database.open()
+        root = connection.root()
+        transaction.begin()
+        root['blob'] = Blob()
+        transaction.commit()
+
+        stream = StringIO()
+        p = Pickler(stream, 1)
+        p.dump(root['blob'])
+        u = Unpickler(stream)
+        stream.seek(0)
+        clone = u.load()
+        clone._p_invalidate()
+
+
+class BlobUndoTests(BlobTests):
+
     def testUndoWithoutPreviousVersion(self):
         base_storage = FileStorage(self.storagefile)
         blob_storage = BlobStorage(self.blob_dir, base_storage)



More information about the Zodb-checkins mailing list