Skip to content

Conversation

@hallvictoria
Copy link
Contributor

Description

Previously, the cache for deferred bindings returned a client based on the resource it was attached to. Therefore, two functions that had client types pointed to the same resource would receive the same client.

For example, these two functions would both use the same client when executing because the blob is the same:

@app.route(route="stream_upload")
@app.blob_input(
    arg_name="client",
    path="streamingtest/tech_blog.mp4",
    connection="DeferredBindingConnectionString"
)
async def stream_upload(req: Request, client: blob.AioBlobClient) -> str:
   async with client:
    await client.create_append_blob()
    await stream_upload(client, req)
    
    return "Uploaded to blob"    


@app.route(route="stream_download")
@app.blob_input(
    arg_name="client",
    path="streamingtest/tech_blog.mp4",
    connection="DeferredBindingConnectionString"
)
async def stream_download(req: Request, client: blob.AioBlobClient):
    props = await client.get_blob_properties()
    return "OK"

This causes an issue specifically for async client types and does not affect sync client types. After stream_upload is executed and stream_download is called, await client.get_blob_properties() will fail with AttributeError: 'NoneType' object has no attribute '__aenter__'. This is an issue that also occurs when using azure-storage-blob-aio directly.

This changes the cache to take in the function name as an additional part of the key so that client types will be unique based on the function.

Fixes #


PR information

  • The title of the PR is clear and informative.
  • There are a small number of commits, each of which has an informative message. This means that previously merged commits do not appear in the history of the PR. For information on cleaning up the commits in your pull request, see this page.
  • If applicable, the PR references the bug/issue that it fixes in the description.
  • New Unit tests were added for the changes made and CI is passing.

Quality of Code and Contribution Guidelines

@hallvictoria hallvictoria marked this pull request as ready for review May 2, 2024 21:07
@hallvictoria hallvictoria merged commit eda9826 into dev Aug 15, 2024
@hallvictoria hallvictoria deleted the hallvictoria/async-cache branch August 15, 2024 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants