Skip to content

[Storage] Download/Upload Blob APIs Fixes for Transport Compatibility #40490

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

weirongw23-msft
Copy link
Member

Need a way to figure out how to mock AsyncioRequestsTransport, then remove the live test only pytest marker

@github-actions github-actions bot added the Storage Storage Service (Queues, Blobs, Files) label Apr 13, 2025
@@ -45,10 +45,6 @@ async def retry_hook(settings, **kwargs):
async def is_checksum_retry(response):
# retry if invalid content md5
if response.context.get('validate_content', False) and response.http_response.headers.get('content-md5'):
try:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adapted sync code to async upload is_checksum_retry

await data.response.load_body()
content = cast(bytes, data.response.body())
if hasattr(data.response, "read"):
content = b"".join([d async for d in data])
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

__anext__ will automatically call read, so this represents any transport that supports read and should also be compatible with decompression

if hasattr(data.response, "read"):
content = b"".join([d async for d in data])
else:
await data.response.load_body()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

decompression could get tricky here

@azure-sdk
Copy link
Collaborator

API change check

API changes are not detected in this pull request.


@pytest.mark.live_test_only
@BlobPreparer()
async def test_core_transport(self, **kwargs):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to fix these tests by mocking the core transport in order to remove the mark live test only.

In test_helpers_async.py, the MockAsyncResponse is required to have a raw attribute that is closeable. The AsyncioRequestsTransport has several attributes populated, and the content read is treated like a file pointer, which needs to be cleaned up.

This is why i've switched to using just the AsyncioRequestsTransport for now. If we do decide to not mock this object directly, there needs to be a call to _setup() and container_name becomes self.container_name.

@@ -46,8 +46,11 @@
async def process_content(data: Any, start_offset: int, end_offset: int, encryption: Dict[str, Any]) -> bytes:
if data is None:
raise ValueError("Response cannot be None.")
await data.response.load_body()
content = cast(bytes, data.response.body())
if hasattr(data.response, "load_body"):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is try-except necessary here? File share already has try-except built-in the process_content.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like transports support either read or load_body, so this should cover all the cases regardless.

@weirongw23-msft weirongw23-msft marked this pull request as ready for review April 13, 2025 17:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Storage Storage Service (Queues, Blobs, Files)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants