MicrosoftDocs / azure-docs

Open source documentation of Microsoft Azure
https://docs.microsoft.com/azure
Creative Commons Attribution 4.0 International
10k stars 21k forks source link

Problem in generated python annotation #122176

Closed matyjas closed 2 weeks ago

matyjas commented 2 weeks ago

When following the instructions for Azure Functions local development in Python using Command Line Tools on Ubuntu 20.04; on running func start the following error appears:

Worker failed to index functions
[2024-05-02T14:17:43.729Z] Result: Failure
[2024-05-02T14:17:43.730Z] Exception: AttributeError: Anonymous
[2024-05-02T14:17:43.730Z] Stack:   File "/usr/lib/azure-functions-core-tools-4/workers/python/3.8/LINUX/X64/azure_functions_worker/dispatcher.py", line 348, in _handle__functions_metadata_request
[2024-05-02T14:17:43.730Z]     fx_metadata_results = self.index_functions(function_path)
[2024-05-02T14:17:43.730Z]   File "/usr/lib/azure-functions-core-tools-4/workers/python/3.8/LINUX/X64/azure_functions_worker/dispatcher.py", line 633, in index_functions
[2024-05-02T14:17:43.730Z]     indexed_functions = loader.index_function_app(function_path)
[2024-05-02T14:17:43.730Z]   File "/usr/lib/azure-functions-core-tools-4/workers/python/3.8/LINUX/X64/azure_functions_worker/utils/wrappers.py", line 44, in call
[2024-05-02T14:17:43.730Z]     return func(*args, **kwargs)
[2024-05-02T14:17:43.730Z]   File "/usr/lib/azure-functions-core-tools-4/workers/python/3.8/LINUX/X64/azure_functions_worker/loader.py", line 222, in index_function_app
[2024-05-02T14:17:43.731Z]     imported_module = importlib.import_module(module_name)
[2024-05-02T14:17:43.731Z]   File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
[2024-05-02T14:17:43.731Z]     return _bootstrap._gcd_import(name[level:], package, level)
[2024-05-02T14:17:43.731Z]   File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
[2024-05-02T14:17:43.731Z]   File "<frozen importlib._bootstrap>", line 991, in _find_and_load
[2024-05-02T14:17:43.731Z]   File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
[2024-05-02T14:17:43.731Z]   File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
[2024-05-02T14:17:43.731Z]   File "<frozen importlib._bootstrap_external>", line 848, in exec_module
[2024-05-02T14:17:43.732Z]   File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
[2024-05-02T14:17:43.732Z]   File "/home/.../function_app.py", line 14, in <module>
[2024-05-02T14:17:43.732Z]     @app.route(route="HttpExample", auth_level=func.AuthLevel.Anonymous)
[2024-05-02T14:17:43.732Z]   File "/usr/lib/python3.8/enum.py", line 384, in __getattr__
[2024-05-02T14:17:43.732Z]     raise AttributeError(name) from None

which is resolved by commenting out half the annotation as in the following example:

@app.route(route="HttpExample") #, auth_level=func.AuthLevel.Anonymous)
def HttpExample(req: func.HttpRequest) -> func.HttpResponse:

Document Details

Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.

PesalaPavan commented 2 weeks ago

@matyjas Thanks for your feedback! We will investigate and update as appropriate.

Venkateshdodda-MSFT commented 2 weeks ago

@matyjas Instead of commenting the below line of code in function_app.py file.

@app.route(route="HttpExample") #, auth_level=func.AuthLevel.Anonymous)
def HttpExample(req: func.HttpRequest) -> func.HttpResponse:

Please try the any of the below work around to run the function without any issues.

Work Around 1:

@app.route(route="HttpExample", auth_level=func.AuthLevel.ANONYMOUS)
def HttpExample(req: func.HttpRequest) -> func.HttpResponse:

WorkAround 2:

app = func.FunctionApp(http_auth_level=func.AuthLevel.ANONYMOUS)
@app.route(route="HttpExample")
def HttpExample(req: func.HttpRequest) -> func.HttpResponse:
    logging.info('Python HTTP trigger function processed a request.')

Also, I see there is an active issue related to this which is reported in Azure function tool github repo here #3651.

I would suggest you follow the latest discussion over there. We will close this out, but if you feel you need more information, please just let us know.