[Zodb-checkins] SVN: ZODB/trunk/src/ Fix Blob bug which prevented opening of blobs with no committed data using either mode 'r+' or 'a'.
Patrick Strawderman
patrick at zope.com
Mon Aug 24 10:36:26 EDT 2009
Log message for revision 103153:
Fix Blob bug which prevented opening of blobs with no committed data using either mode 'r+' or 'a'.
Changed:
U ZODB/trunk/src/CHANGES.txt
U ZODB/trunk/src/ZODB/blob.py
U ZODB/trunk/src/ZODB/tests/blob_basic.txt
-=-
Modified: ZODB/trunk/src/CHANGES.txt
===================================================================
--- ZODB/trunk/src/CHANGES.txt 2009-08-24 14:35:52 UTC (rev 103152)
+++ ZODB/trunk/src/CHANGES.txt 2009-08-24 14:36:26 UTC (rev 103153)
@@ -22,6 +22,9 @@
- Objects defining _p_deactivate methods that didn't call base methods
weren't loaded properly. https://bugs.launchpad.net/zodb/+bug/185066
+- Opening a blob with modes 'r+' or 'a' would fail when the blob had no
+ committed changes.
+
3.9.0b5 (2009-08-06)
====================
Modified: ZODB/trunk/src/ZODB/blob.py
===================================================================
--- ZODB/trunk/src/ZODB/blob.py 2009-08-24 14:35:52 UTC (rev 103152)
+++ ZODB/trunk/src/ZODB/blob.py 2009-08-24 14:36:26 UTC (rev 103153)
@@ -169,14 +169,15 @@
if self._p_blob_uncommitted is None:
self._create_uncommitted_file()
result = BlobFile(self._p_blob_uncommitted, mode, self)
- else:
+ else: # 'r+' and 'a'
if self._p_blob_uncommitted is None:
# Create a new working copy
self._create_uncommitted_file()
result = BlobFile(self._p_blob_uncommitted, mode, self)
- utils.cp(file(self._p_blob_committed), result)
- if mode == 'r+':
- result.seek(0)
+ if self._p_blob_committed:
+ utils.cp(open(self._p_blob_committed), result)
+ if mode == 'r+':
+ result.seek(0)
else:
# Re-use existing working copy
result = BlobFile(self._p_blob_uncommitted, mode, self)
Modified: ZODB/trunk/src/ZODB/tests/blob_basic.txt
===================================================================
--- ZODB/trunk/src/ZODB/tests/blob_basic.txt 2009-08-24 14:35:52 UTC (rev 103152)
+++ ZODB/trunk/src/ZODB/tests/blob_basic.txt 2009-08-24 14:36:26 UTC (rev 103153)
@@ -156,6 +156,19 @@
'rb'
>>> f9.close()
+Blobs that have not been committed can be opened using any mode,
+except for "c"::
+
+ >>> from ZODB.blob import BlobError, valid_modes
+ >>> for mode in valid_modes:
+ ... try:
+ ... f10 = Blob().open(mode)
+ ... except BlobError:
+ ... print 'open failed with mode "%s"' % mode
+ ... else:
+ ... f10.close()
+ open failed with mode "c"
+
Some cleanup in this test is needed::
>>> import transaction
More information about the Zodb-checkins
mailing list