[Zodb-checkins] SVN: ZODB/branches/blob-merge-branch/src/ZODB/Blobs/ - added test for special undo situation

Christian Theune ct at gocept.com
Tue Feb 28 13:02:38 EST 2006


Log message for revision 65600:
   - added test for special undo situation
   - added small non-yet-working work-around
  

Changed:
  U   ZODB/branches/blob-merge-branch/src/ZODB/Blobs/BlobStorage.py
  U   ZODB/branches/blob-merge-branch/src/ZODB/Blobs/tests/test_undo.py

-=-
Modified: ZODB/branches/blob-merge-branch/src/ZODB/Blobs/BlobStorage.py
===================================================================
--- ZODB/branches/blob-merge-branch/src/ZODB/Blobs/BlobStorage.py	2006-02-28 17:17:12 UTC (rev 65599)
+++ ZODB/branches/blob-merge-branch/src/ZODB/Blobs/BlobStorage.py	2006-02-28 18:02:38 UTC (rev 65600)
@@ -193,14 +193,20 @@
         return orig_size + blob_size
 
     def undo(self, serial_id, transaction):
+        import pdb; pdb.set_trace() 
         serial, keys = getProxiedObject(self).undo(serial_id, transaction)
         self._lock_acquire()
         try:
             # The old serial_id is given in base64 encoding ...
             serial_id = base64.decodestring(serial_id+ '\n')
             for oid in self.fshelper.getOIDsForSerial(serial_id):
-                data, serial_before, serial_after = self.loadBefore(oid,
-                                                                    serial_id) 
+                load_result = self.loadBefore(oid, serial_id) 
+
+                if load_result is None:
+                    continue
+
+                data, serial_before, serial_after = load_result
+                                                    
                 orig_fn = self.fshelper.getBlobFilename(oid, serial_before)
                 orig = open(orig_fn, "r")
                 new_fn = self.fshelper.getBlobFilename(oid, serial)

Modified: ZODB/branches/blob-merge-branch/src/ZODB/Blobs/tests/test_undo.py
===================================================================
--- ZODB/branches/blob-merge-branch/src/ZODB/Blobs/tests/test_undo.py	2006-02-28 17:17:12 UTC (rev 65599)
+++ ZODB/branches/blob-merge-branch/src/ZODB/Blobs/tests/test_undo.py	2006-02-28 18:02:38 UTC (rev 65600)
@@ -37,6 +37,26 @@
             pass
         shutil.rmtree(self.blob_dir)
 
+    def testUndoWithoutPreviousVersion(self):
+        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()
+        blob = Blob()
+        blob.open('w').write('this is state 1')
+        root['blob'] = blob
+        transaction.commit()
+
+        serial = base64.encodestring(blob_storage._tid)
+
+        transaction.begin()
+        blob_storage.undo(serial, blob_storage._transaction)
+        transaction.commit()
+
+        self.assertRaises(KeyError, root.__getitem__, 'blob')
+
     def testUndo(self):
         base_storage = FileStorage(self.storagefile)
         blob_storage = BlobStorage(self.blob_dir, base_storage)



More information about the Zodb-checkins mailing list