Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sdk/storage/azure-storage-blob/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Features Added

### Bugs Fixed
- Removed forced `requests` import for sync calls. (25017)
- Adjusted type hints for `upload_blob` and `StorageStreamDownloader.readall`.

## 12.13.0 (2022-07-07)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
from io import BytesIO
from typing import Generic, Iterator, TypeVar

import requests
from azure.core.exceptions import HttpResponseError, ServiceResponseError
from azure.core.exceptions import DecodeError, HttpResponseError, ServiceResponseError, IncompleteReadError
from azure.core.tracing.common import with_current_context

from ._shared.request_handlers import validate_and_format_range_headers
Expand Down Expand Up @@ -213,7 +212,7 @@ def _download_chunk(self, chunk_start, chunk_end):
try:
chunk_data = process_content(response, offset[0], offset[1], self.encryption_options)
retry_active = False
except (requests.exceptions.ChunkedEncodingError, requests.exceptions.ConnectionError) as error:
Comment thread
jalauzon-msft marked this conversation as resolved.
except (IncompleteReadError, HttpResponseError, DecodeError) as error:
retry_total -= 1
if retry_total <= 0:
raise ServiceResponseError(error, error=error)
Expand Down Expand Up @@ -474,7 +473,7 @@ def _initial_request(self):
self._encryption_options
)
retry_active = False
except (requests.exceptions.ChunkedEncodingError, requests.exceptions.ConnectionError) as error:
except (IncompleteReadError, HttpResponseError, DecodeError) as error:
retry_total -= 1
if retry_total <= 0:
raise ServiceResponseError(error, error=error)
Expand Down
35 changes: 30 additions & 5 deletions sdk/storage/azure-storage-blob/tests/test_retry.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
import unittest
from unittest import mock
import pytest

from azure.core.exceptions import (
HttpResponseError,
ResourceExistsError,
AzureError,
ClientAuthenticationError
ClientAuthenticationError,
ServiceResponseError
)
from azure.core.pipeline.transport import(
RequestsTransport
Expand All @@ -24,6 +25,9 @@
LinearRetry,
ExponentialRetry,
)
from requests import Response
from requests.exceptions import ContentDecodingError, ChunkedEncodingError
from azure.core.exceptions import DecodeError

from settings.testcase import BlobPreparer
from devtools_testutils.storage import StorageTestCase
Expand Down Expand Up @@ -434,6 +438,27 @@ def test_invalid_account_key(self, storage_account_name, storage_account_key):
# No retry should be performed since the signing error is fatal
self.assertEqual(retry_counter.count, 0)


# ------------------------------------------------------------------------------

@pytest.mark.live_test_only
Comment thread
jalauzon-msft marked this conversation as resolved.
Outdated
@BlobPreparer()
def test_streaming_retry(self, storage_account_name, storage_account_key):
"""Test that retry mechanisms are working when streaming data."""
container_name = self.get_resource_name('utcontainer')
service = self._create_storage_service(
BlobServiceClient, storage_account_name, storage_account_key)
container = service.get_container_client(container_name)
container.create_container()
assert container.exists()
blob_name = "myblob"
container.upload_blob(blob_name, b"abcde")

for error in (ContentDecodingError(), ChunkedEncodingError(), ChunkedEncodingError("IncompleteRead")):
iterator_mock = mock.MagicMock()
iterator_mock.__next__.side_effect = error
iter_content_mock = mock.Mock()
iter_content_mock.return_value = iterator_mock
with mock.patch.object(Response, "iter_content", iter_content_mock), pytest.raises(ServiceResponseError):
blob = container.get_blob_client(blob=blob_name)
blob.download_blob()
assert iterator_mock.__next__.call_count == 3

# ------------------------------------------------------------------------------