diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 1d289a020435ff72b547640dac18f908072b0f3e..e2f5d5538f1402bf984cf5a90f17fbdd38f44711 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -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) ==================== diff --git a/src/ZODB/blob.py b/src/ZODB/blob.py index 4f10e38c48be94da9e142f8bedd3ae5e90339876..ba7bf115c5480afacb2b7ce2fdf37a5ee3a45b7e 100644 --- a/src/ZODB/blob.py +++ b/src/ZODB/blob.py @@ -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) diff --git a/src/ZODB/tests/blob_basic.txt b/src/ZODB/tests/blob_basic.txt index e42f34fdb154c5cca850d1f5f9aec8f068c54765..4aaa0d3afb3cb3507155e64dcc6340f1f239d045 100644 --- a/src/ZODB/tests/blob_basic.txt +++ b/src/ZODB/tests/blob_basic.txt @@ -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