Azure / azure-functions-durable-python

Python library for using the Durable Functions bindings.
MIT License
134 stars 51 forks source link

binding <name> has invalid non-type annotation list[str] #468

Open mumurug-MSFT opened 7 months ago

mumurug-MSFT commented 7 months ago

🐛 Describe the bug When running durable function activity in 3.11, it throws the below error:

Exception: FunctionLoadError: cannot load the Hello1 function: binding payload has invalid non-type annotation list[str] Stack: File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.11/WINDOWS/X64\azure_functions_worker\dispatcher.py", line 393, in _handle__function_load_request self._functions.add_function( File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.11/WINDOWS/X64\azure_functions_worker\functions.py", line 338, in add_function input_types, output_types = self.validate_function_params(params, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.11/WINDOWS/X64\azure_functions_worker\functions.py", line 185, in validate_function_params raise FunctionLoadError(

However, the same works fine in 3.10.

🤔 Expected behavior Should run without any errors/exception.

Steps to reproduce Core Tools Version: 4.0.5455 Commit hash: N/A (64-bit) Function Runtime Version: 4.27.5.21554

Create a durable function activity in VS Code (v.13.1 - azure function extension) with the following code:

init.py `import asyncio import azure.functions as func

async def main( payload: list[str] , outputblob: func.Out[str] ) -> str: outputblob.set( payload[0] + payload[1] ) return("Finalout")`

function.json { "scriptFile": "__init__.py", "bindings": [ { "name": "payload", "type": "activityTrigger", "direction": "in" } ], "disabled": false }

Then run in debug mode and you will find the above exception in terminal window.

If deployed to Azure ran it in local machine

danielniccoli commented 6 months ago

I also have this issue after adding changing a type into a Union type.

Works

@bp.activity_trigger(input_name="grouprequest")
@bp.durable_client_input(client_name="client")
async def prestage_graph_group(
    grouprequest: SecurityGroupRequest, client
) -> dict:
    ...

Fails

@bp.activity_trigger(input_name="grouprequest")
@bp.durable_client_input(client_name="client")
async def prestage_graph_group(
    grouprequest: SecurityGroupRequest | M365GroupRequest, client
) -> dict:
    ...

with

[2024-01-18T17:01:58.903Z] Worker failed to index functions
[2024-01-18T17:01:58.905Z] Result: Failure
Exception: FunctionLoadError: cannot load the validate_group_properties function: binding grouprequest has invalid non-type annotation models.SecurityGroupRequest | models.M365GroupRequest
Stack:   File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.11/WINDOWS/X64\azure_functions_worker\dispatcher.py", line 345, in _handle__functions_metadata_request
    fx_metadata_results = self.index_functions(function_path)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.11/WINDOWS/X64\azure_functions_worker\dispatcher.py", line 622, in index_functions
    fx_metadata_results = loader.process_indexed_function(
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.11/WINDOWS/X64\azure_functions_worker\loader.py", line 126, in process_indexed_function
    function_info = functions_registry.add_indexed_function(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.11/WINDOWS/X64\azure_functions_worker\functions.py", line 392, in add_indexed_function
    input_types, output_types = self.validate_function_params(params,
                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.11/WINDOWS/X64\azure_functions_worker\functions.py", line 185, in validate_function_params
    raise FunctionLoadError(

I'm using Python 3.11

Goldziher commented 2 months ago

same:

@blueprint.activity_trigger(input_name="file_parameters")
async def handle_file_download(
    file_parameters: tuple[str, str, FileData],
) -> tuple[str, str, float]:
     ...

Stack:

[2024-04-26T09:11:42.895Z] Worker failed to index functions
[2024-04-26T09:11:42.895Z] Result: Failure
[2024-04-26T09:11:42.895Z] Exception: FunctionLoadError: cannot load the handle_file_download function: binding file_parameters has invalid non-type annotation tuple[str, str, functions.syncer.types.FileData]
[2024-04-26T09:11:42.895Z] Stack:   File "/opt/homebrew/Cellar/azure-functions-core-tools@4/4.0.5611/workers/python/3.11/OSX/Arm64/azure_functions_worker/dispatcher.py", line 348, in _handle__functions_metadata_request
[2024-04-26T09:11:42.895Z]     fx_metadata_results = self.index_functions(function_path)
[2024-04-26T09:11:42.895Z]                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[2024-04-26T09:11:42.895Z]   File "/opt/homebrew/Cellar/azure-functions-core-tools@4/4.0.5611/workers/python/3.11/OSX/Arm64/azure_functions_worker/dispatcher.py", line 638, in index_functions
[2024-04-26T09:11:42.895Z]     fx_metadata_results = loader.process_indexed_function(
[2024-04-26T09:11:42.895Z]                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[2024-04-26T09:11:42.895Z]   File "/opt/homebrew/Cellar/azure-functions-core-tools@4/4.0.5611/workers/python/3.11/OSX/Arm64/azure_functions_worker/loader.py", line 128, in process_indexed_function
[2024-04-26T09:11:42.895Z]     function_info = functions_registry.add_indexed_function(
[2024-04-26T09:11:42.895Z]                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[2024-04-26T09:11:42.895Z]   File "/opt/homebrew/Cellar/azure-functions-core-tools@4/4.0.5611/workers/python/3.11/OSX/Arm64/azure_functions_worker/functions.py", line 392, in add_indexed_function
[2024-04-26T09:11:42.895Z]     input_types, output_types = self.validate_function_params(params,
[2024-04-26T09:11:42.895Z]                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[2024-04-26T09:11:42.895Z]   File "/opt/homebrew/Cellar/azure-functions-core-tools@4/4.0.5611/workers/python/3.11/OSX/Arm64/azure_functions_worker/functions.py", line 185, in validate_function_params
[2024-04-26T09:11:42.895Z]     raise FunctionLoadError(
[2024-04-26T09:11:42.895Z] .
arjendev commented 2 days ago

After migrating to python 3.11, we are having a similar issue on dictionary input bindings:


@some_blueprint.activity_trigger(input_name="some_model", activity="SOME_ACTIVITY")
async def create_monitor_activity(some_model: dict[str, Any]):
    ...

With error on starting the host:

Worker failed to index functions
[2024-07-17T13:53:59.933Z] Result: Failure
[2024-07-17T13:53:59.933Z] Exception: FunctionLoadError: cannot load the create_monitor_activity function: binding some_model has invalid non-type annotation dict[str, typing.Any]
[2024-07-17T13:53:59.933Z] Stack:   File "/usr/lib/azure-functions-core-tools/workers/python/3.11/LINUX/X64/azure_functions_worker/dispatcher.py", line 413, in _handle__functions_metadata_request