azure-functions-python-worker
azure-functions-python-worker copied to clipboard
[Bug] Blob trigger uses incorrect authentication method
Expected Behavior
When using identity-based connection settings it should use the managed identity auth method.
Actual Behavior
It tries to use the connection string method and fails because it tries to parse a non-existent setting.
Steps to Reproduce
- Create identity-based connections in the environment variables, in this case:
DATALAKE__queueServiceUri
&DATALAKE__blobServiceUri
- Create a blob trigger using
connection="DATALAKE"
- Create a test blob in the path defined for the blob trigger
- It will result into erroring parsing the non-existent "DATALAKE" env variable.
If you use the AzureWebJobsStorage__accountname
and set connection="AzureWebJobsStorage"
without having the AzureWebJobsStorage
setting it works, so it's only for custom connections which are documented here
Relevant code being tried
{
"IsEncrypted": false,
"Values": {
"FUNCTIONS_WORKER_RUNTIME": "python",
"AzureWebJobsFeatureFlags": "EnableWorkerIndexing",
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"DATALAKE__blobServiceUri": "https://REDACTED.blob.core.windows.net/",
"DATALAKE__serviceUri": "https://REDACTED.blob.core.windows.net/",
"DATALAKE__queueServiceUri": "https://REDACTED.queue.core.windows.net/"
}
}
import logging
import os
import azure.functions as func
from azure.identity import DefaultAzureCredential
from azure.storage.blob import BlobClient
import azurefunctions.extensions.bindings.blob as blob
bp = func.Blueprint()
@bp.function_name(name="process_blob_weather_data")
@bp.blob_trigger(
arg_name="sourceblob", path="bronze/weatherdata/{name}.json", connection="DATALAKE"
)
def process_blob_weather_data(sourceblob: blob.BlobClient):
logging.info('Starting to process blob')
logging.info(
f"Python blob trigger function processed blob! Perms \n"
f"Properties: {sourceblob.get_blob_properties()}\n"
f"Blob content head: {sourceblob.download_blob().read(size=1)}"
)
logging.info('Blob processed')
Relevant log output
ContextEnabledTask exception was never retrieved
future: <ContextEnabledTask finished name='Task-8' coro=<Dispatcher._dispatch_grpc_request() done, defined at C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.11\WINDOWS\X64\azure_functions_worker\dispatcher.py:263> exception=UnboundLocalError("cannot access local variable 'http_v2_enabled' where it is not associated with a value")>
Traceback (most recent call last):
File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.11\WINDOWS\X64\azure_functions_worker\dispatcher.py", line 565, in _handle__invocation_request
args[pb.name] = bindings.from_incoming_proto(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.11\WINDOWS\X64\azure_functions_worker\bindings\meta.py", line 183, in from_incoming_proto
return deferred_bindings_decode(binding=binding,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.11\WINDOWS\X64\azure_functions_worker\bindings\meta.py", line 301, in deferred_bindings_decode
deferred_binding_type = binding.decode(datum,
^^^^^^^^^^^^^^^^^^^^^
File "C:\Source\InSparkSolutions\smallestAzureDataplatform\functions\.venv\Lib\site-packages\azurefunctions\extensions\bindings\blob\blobClientConverter.py", line 43, in decode
return BlobClient(data=data).get_sdk_type()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Source\InSparkSolutions\smallestAzureDataplatform\functions\.venv\Lib\site-packages\azurefunctions\extensions\bindings\blob\blobClient.py", line 35, in get_sdk_type
return BlobClientSdk.from_connection_string(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Source\InSparkSolutions\smallestAzureDataplatform\functions\.venv\Lib\site-packages\azure\storage\blob\_blob_client.py", line 347, in from_connection_string
account_url, secondary, credential = parse_connection_str(conn_str, credential, 'blob')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Source\InSparkSolutions\smallestAzureDataplatform\functions\.venv\Lib\site-packages\azure\storage\blob\_shared\base_client.py", line 368, in parse_connection_str
conn_str = conn_str.rstrip(";")
^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'rstrip'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.11\WINDOWS\X64\azure_functions_worker\dispatcher.py", line 274, in _dispatch_grpc_request
resp = await request_handler(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.11\WINDOWS\X64\azure_functions_worker\dispatcher.py", line 655, in _handle__invocation_request
if http_v2_enabled:
^^^^^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'http_v2_enabled' where it is not associated with a value
requirements.txt file
azure-functions pandas requests azure-identity azure-storage-blob azurefunctions-extensions-bindings-blob
Where are you facing this problem?
Local - Core Tools
Function app name
No response
Additional Information
No response