Azure / azure-functions-core-tools

Command line tools for Azure Functions
MIT License
1.28k stars 423 forks source link

Python template incorrectly updated #3695

Open RyanHill-MSFT opened 1 month ago

RyanHill-MSFT commented 1 month ago

See MicrosoftDocs/azure-docs#122596.

If the --auth parameter is passed into func new CLI command, the AuthLevel for Python is set in CamelCase which doesn't match Azure Python SDK

roboticsbrian commented 1 month ago

I can confirm this issue with 4.0.5801:

$ func start
Found Python version 3.8.10 (python3).

Azure Functions Core Tools
Core Tools Version:       4.0.5801 Commit hash: N/A +5ac2f09758b98257e728dd1b5576ce5ea9ef68ff (64-bit)
Function Runtime Version: 4.34.1.22669

[2024-06-06T05:31:25.294Z] Worker failed to index functions
[2024-06-06T05:31:25.294Z] Result: Failure
[2024-06-06T05:31:25.294Z] Exception: AttributeError: Anonymous
[2024-06-06T05:31:25.294Z] Stack:   File "/usr/lib/azure-functions-core-tools-4/workers/python/3.8/LINUX/X64/azure_functions_worker/dispatcher.py", line 413, in _handle__functions_metadata_request
[2024-06-06T05:31:25.294Z]     self.load_function_metadata(
[2024-06-06T05:31:25.294Z]   File "/usr/lib/azure-functions-core-tools-4/workers/python/3.8/LINUX/X64/azure_functions_worker/dispatcher.py", line 393, in load_function_metadata
[2024-06-06T05:31:25.294Z]     self.index_functions(function_path, function_app_directory)) \
[2024-06-06T05:31:25.294Z]   File "/usr/lib/azure-functions-core-tools-4/workers/python/3.8/LINUX/X64/azure_functions_worker/dispatcher.py", line 765, in index_functions
[2024-06-06T05:31:25.294Z]     indexed_functions = loader.index_function_app(function_path)
[2024-06-06T05:31:25.294Z]   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-06-06T05:31:25.294Z]     return func(*args, **kwargs)
[2024-06-06T05:31:25.294Z]   File "/usr/lib/azure-functions-core-tools-4/workers/python/3.8/LINUX/X64/azure_functions_worker/loader.py", line 238, in index_function_app
[2024-06-06T05:31:25.294Z]     imported_module = importlib.import_module(module_name)
[2024-06-06T05:31:25.294Z]   File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
[2024-06-06T05:31:25.294Z]     return _bootstrap._gcd_import(name[level:], package, level)
[2024-06-06T05:31:25.294Z]   File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
[2024-06-06T05:31:25.294Z]   File "<frozen importlib._bootstrap>", line 991, in _find_and_load
[2024-06-06T05:31:25.294Z]   File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
[2024-06-06T05:31:25.294Z]   File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
[2024-06-06T05:31:25.294Z]   File "<frozen importlib._bootstrap_external>", line 848, in exec_module
[2024-06-06T05:31:25.294Z]   File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
[2024-06-06T05:31:25.294Z]   File "/home/brian/Code/azurefunc/function_app.py", line 8, in <module>
[2024-06-06T05:31:25.294Z]     @app.route(route="HttpExample", auth_level=func.AuthLevel.Anonymous)
[2024-06-06T05:31:25.294Z]   File "/usr/lib/python3.8/enum.py", line 384, in __getattr__
[2024-06-06T05:31:25.294Z]     raise AttributeError(name) from None
[2024-06-06T05:31:25.294Z] .

and in function_app.py:

import azure.functions as func
import datetime
import json
import logging

app = func.FunctionApp()

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

Changing it to func.AuthLevel.ANONYMOUS lets the API run as expected.

fingineering commented 2 weeks ago

Still an issue in 4.0.5858