Skip to content
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

fix: unique clients per function #1490

Merged
merged 9 commits into from
Aug 15, 2024
Merged

fix: unique clients per function #1490

merged 9 commits into from
Aug 15, 2024

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
25 of 27 checks passed
@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.

2 participants