Skip to content

Commit

Permalink
Fix: BlobWriter.close() will do nothing if already closed
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewsg committed Oct 12, 2022
1 parent 3d84972 commit 49cc29c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 2 additions & 3 deletions google/cloud/storage/fileio.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,9 +423,8 @@ def flush(self):
)

def close(self):
self._checkClosed() # Raises ValueError if closed.

self._upload_chunks_from_buffer(1)
if not self._buffer.closed:
self._upload_chunks_from_buffer(1)
self._buffer.close()

def _checkClosed(self):
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/test_fileio.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,9 @@ def test_write(self, mock_warn):
stacklevel=2,
)

# Close a second time to verify it successfully does nothing.
writer.close()

def test_flush_fails(self):
blob = mock.Mock(chunk_size=None)
writer = self._make_blob_writer(blob)
Expand Down

0 comments on commit 49cc29c

Please sign in to comment.