azure-functions-python-worker icon indicating copy to clipboard operation
azure-functions-python-worker copied to clipboard

fix: unique clients per function

Open hallvictoria opened this issue 9 months ago • 0 comments

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 avatar May 02 '24 18:05 hallvictoria