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
- 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)
====================
......
......@@ -169,14 +169,15 @@ class Blob(persistent.Persistent):
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)
......
......@@ -156,6 +156,19 @@ Blobs are always opened in binary mode::
'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
......
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