Azure / azure-functions-python-worker

Python worker for Azure Functions.
http://aka.ms/azurefunctions
MIT License
332 stars 100 forks source link

"1 functions found; 0 functions loaded" when running Python V2 function with identity-based connection #1288

Closed tfrederick74656 closed 7 months ago

tfrederick74656 commented 1 year ago

Summary

When running the VS code starter/sample Python V2 TimerTrigger function with an identity-based connection (e.g. system-assigned managed identity and no AzureWebJobsStorage app setting), no functions are loaded. I'm not sure if this is a bug, if there's a documentation oversight, or if I'm simply missing a step.

Investigative information

Repro steps

  1. Create a new empty Function App via the portal: Python 3.10, East US, Linux, Consumption
  2. Enable the system-assigned managed identity on the Function App
  3. Assign the managed identity the Storage Blob Data Owner role on the storage account, as documented here for both "No extension" and "Timer trigger".
  4. Remove the AzureWebJobsStorage app setting and add AzureWebJobsStorage__accountName with the name of the storage account as the value, as documented here.
  5. Create a new Python V2 function in VS Code using the default TimerTrigger starter.
  6. From VS Code, deploy the function to the function app in Azure.

Expected behavior

The function app should execute normally.

Actual behavior

The function never executes and the following is observed in log stream and traces:

2023-07-12T20:59:33Z   [Information]   Loading functions metadata
2023-07-12T20:59:33Z   [Information]   Reading functions metadata
2023-07-12T20:59:33Z   [Information]   1 functions found
2023-07-12T20:59:33Z   [Information]   0 functions loaded

Additionally, the function does not appear in the Functions blade of the Function App.

Known workarounds

When the AzureWebJobsStorage app setting is in place, the function app works as expected -- the function is listed in the portal blade, loads, and executes successfully on the default 1-minute timer interval. It is only when using the AzureWebJobsStorage__accountName app setting and identity-based connection that the function fails to load.

Related information

Source **function_app.py** ```python import datetime import logging import azure.functions as func app = func.FunctionApp() @app.schedule(schedule="0 * * * * *", arg_name="myTimer", run_on_startup=True, use_monitor=False) def TimerTrigger(myTimer: func.TimerRequest) -> None: utc_timestamp = datetime.datetime.utcnow().replace( tzinfo=datetime.timezone.utc).isoformat() if myTimer.past_due: logging.info('The timer is past due!') logging.info('Python timer trigger function ran at %s', utc_timestamp) ``` **host.json** ```json { "version": "2.0", "logging": { "applicationInsights": { "samplingSettings": { "isEnabled": true, "excludedTypes": "Request" } } }, "extensionBundle": { "id": "Microsoft.Azure.Functions.ExtensionBundle", "version": "[4.*, 5.0.0)" } } ``` **requirements.txt** ``` # DO NOT include azure-functions-worker in this file # The Python Worker is managed by Azure Functions platform # Manually managing azure-functions-worker may cause unexpected issues azure-functions ``` **Environment Variables** ```json [ { "name": "APPINSIGHTS_INSTRUMENTATIONKEY", "value": "********-****-****-****-************", "slotSetting": false }, { "name": "APPLICATIONINSIGHTS_CONNECTION_STRING", "value": "InstrumentationKey=********-****-****-****-************;IngestionEndpoint=https://eastus-8.in.applicationinsights.azure.com/;LiveEndpoint=https://eastus.livediagnostics.monitor.azure.com/", "slotSetting": false }, { "name": "AzureWebJobsFeatureFlags", "value": "EnableWorkerIndexing", "slotSetting": false }, { "name": "AzureWebJobsStorage__accountName", "value": "devtjffuncpythontest", "slotSetting": false }, { "name": "FUNCTIONS_EXTENSION_VERSION", "value": "~4", "slotSetting": false }, { "name": "FUNCTIONS_WORKER_RUNTIME", "value": "python", "slotSetting": false }, { "name": "WEBSITE_CONTENTAZUREFILECONNECTIONSTRING", "value": "DefaultEndpointsProtocol=https;AccountName=devtjffuncpythontest;AccountKey=****************************************************************************************;EndpointSuffix=core.windows.net", "slotSetting": false }, { "name": "WEBSITE_CONTENTSHARE", "value": "dev-tjf-functions-python-testa876", "slotSetting": false } ] ```
paulyuk commented 1 year ago

Hi @tfrederick74656 - thank you much for the report and contribution. Unfortunately this combination is not supported where you use the tools to create a zipdeploy package, and also configure managed identity on storage, and deploy to Linux Consumption.

The current workaround is to use a server build approach here, not using the tools to build zipdeploy package. https://learn.microsoft.com/en-us/azure/azure-functions/functions-deployment-technologies?tabs=windows

Is that acceptable to you as Azure Functions maintainers work on longer term solution?