Commit 8eb1d702 authored by Patrick Strawderman's avatar Patrick Strawderman

Fix Blob bug which prevented opening of blobs with no committed data using either mode 'r+' or 'a'.

parent 75d9b564
...@@ -22,6 +22,9 @@ Bugs Fixed ...@@ -22,6 +22,9 @@ Bugs Fixed
- Objects defining _p_deactivate methods that didn't call base methods - Objects defining _p_deactivate methods that didn't call base methods
weren't loaded properly. https://bugs.launchpad.net/zodb/+bug/185066 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) 3.9.0b5 (2009-08-06)
==================== ====================
......
...@@ -169,14 +169,15 @@ class Blob(persistent.Persistent): ...@@ -169,14 +169,15 @@ class Blob(persistent.Persistent):
if self._p_blob_uncommitted is None: if self._p_blob_uncommitted is None:
self._create_uncommitted_file() self._create_uncommitted_file()
result = BlobFile(self._p_blob_uncommitted, mode, self) result = BlobFile(self._p_blob_uncommitted, mode, self)
else: else: # 'r+' and 'a'
if self._p_blob_uncommitted is None: if self._p_blob_uncommitted is None:
# Create a new working copy # Create a new working copy
self._create_uncommitted_file() self._create_uncommitted_file()
result = BlobFile(self._p_blob_uncommitted, mode, self) result = BlobFile(self._p_blob_uncommitted, mode, self)
utils.cp(file(self._p_blob_committed), result) if self._p_blob_committed:
if mode == 'r+': utils.cp(open(self._p_blob_committed), result)
result.seek(0) if mode == 'r+':
result.seek(0)
else: else:
# Re-use existing working copy # Re-use existing working copy
result = BlobFile(self._p_blob_uncommitted, mode, self) result = BlobFile(self._p_blob_uncommitted, mode, self)
......
...@@ -156,6 +156,19 @@ Blobs are always opened in binary mode:: ...@@ -156,6 +156,19 @@ Blobs are always opened in binary mode::
'rb' 'rb'
>>> f9.close() >>> 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:: Some cleanup in this test is needed::
>>> import transaction >>> import transaction
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment