Skip to content

Commit

Permalink
Hotfix for the issue where we cannot download the snapshot of a blob …
Browse files Browse the repository at this point in the history
…in chunks. (#282)
  • Loading branch information
asorrin-msft authored and Ram B committed Apr 12, 2017
1 parent 0c736d4 commit 761dd19
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
5 changes: 5 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

> See [BreakingChanges](BreakingChanges.md) for a detailed list of API breaks.
## Version 0.34.1:

### Blob:
- Fixed a bug where downloading the snapshot of a blob will fail in some cases.

## Version 0.34.0:

### All:
Expand Down
7 changes: 5 additions & 2 deletions azure/storage/blob/_download_chunking.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
)
from .._error import _ERROR_NO_SINGLE_THREAD_CHUNKING

def _download_blob_chunks(blob_service, container_name, blob_name,
def _download_blob_chunks(blob_service, container_name, blob_name, snapshot,
download_size, block_size, progress, start_range, end_range,
stream, max_connections, progress_callback, validate_content,
lease_id, if_modified_since, if_unmodified_since, if_match,
Expand All @@ -32,6 +32,7 @@ def _download_blob_chunks(blob_service, container_name, blob_name,
blob_service,
container_name,
blob_name,
snapshot,
download_size,
block_size,
progress,
Expand All @@ -54,13 +55,14 @@ def _download_blob_chunks(blob_service, container_name, blob_name,
result = list(executor.map(downloader.process_chunk, downloader.get_chunk_offsets()))

class _BlobChunkDownloader(object):
def __init__(self, blob_service, container_name, blob_name, download_size,
def __init__(self, blob_service, container_name, blob_name, snapshot, download_size,
chunk_size, progress, start_range, end_range, stream,
progress_callback, validate_content, lease_id, if_modified_since,
if_unmodified_since, if_match, if_none_match, timeout, operation_context):
self.blob_service = blob_service
self.container_name = container_name
self.blob_name = blob_name
self.snapshot = snapshot
self.chunk_size = chunk_size

self.download_size = download_size
Expand Down Expand Up @@ -117,6 +119,7 @@ def _download_chunk(self, chunk_start, chunk_end):
response = self.blob_service._get_blob(
self.container_name,
self.blob_name,
snapshot=self.snapshot,
start_range=chunk_start,
end_range=chunk_end - 1,
validate_content=self.validate_content,
Expand Down
1 change: 1 addition & 0 deletions azure/storage/blob/baseblobservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -1985,6 +1985,7 @@ def get_blob_to_stream(
self,
container_name,
blob_name,
snapshot,
download_size,
self.MAX_CHUNK_GET_SIZE,
first_get_size,
Expand Down
15 changes: 15 additions & 0 deletions tests/test_get_blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,21 @@ def test_get_blob_to_bytes(self):
# Assert
self.assertEqual(self.byte_data, blob.content)

def test_get_blob_to_bytes_snapshot(self):
# parallel tests introduce random order of requests, can only run live
if TestMode.need_recording_file(self.test_mode):
return

# Arrange
snapshot = self.bs.snapshot_blob(self.container_name, self.byte_blob)
self.bs.create_blob_from_bytes(self.container_name, self.byte_blob, self.byte_data) # Modify the blob so the Etag no longer matches

# Act
blob = self.bs.get_blob_to_bytes(self.container_name, self.byte_blob, snapshot.snapshot)

# Assert
self.assertEqual(self.byte_data, blob.content)

def test_get_blob_to_bytes_with_progress(self):
# parallel tests introduce random order of requests, can only run live
if TestMode.need_recording_file(self.test_mode):
Expand Down

0 comments on commit 761dd19

Please sign in to comment.