Azure / azure-functions-python-worker

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

[Bug] EventGrid Trigger Function fails because input binding in function.json does not match Python type annotation #1609

Open bmcandr opened 1 week ago

bmcandr commented 1 week ago

Expected Behavior

The Function should execute without error.

Actual Behavior

The Function fails with an error message saying that the type of the input binding in function.json does not match the Python type annotation of the parameter in the entrypoint function.

Steps to Reproduce

Using Python version 3.10.*:

  1. Create a Function by copying the v1 programming model example in the Azure docs here
  2. Use the pex library to package the Function as an executable zip file (contains Python dependencies and Function-related files like host.json and function.json)
  3. Zip-deploy the packaged Function (e.g., az functionapp deployment source config-zip --src example.zip --build-remote false --name myfunc --resource-group myresourcegroup --verbose)
  4. Execute the Function via the Test/Run interface in the Azure Portal or by triggering an event

Relevant code being tried

The v1 programming model example from the Azure docs here.

Relevant log output

Result: Failure Exception: FunctionLoadError: cannot load the test_pex function: type of event binding in function.json "eventGridTrigger" does not match its Python annotation "EventGridEvent"
Stack: File "/azure-functions-host/workers/python/3.10/LINUX/X64/azure_functions_worker/dispatcher.py", line 541, in _handle__function_load_request self._functions.add_function(
File "/azure-functions-host/workers/python/3.10/LINUX/X64/azure_functions_worker/functions.py", line 392, in add_function input_types, output_types, _ = self.validate_function_params(
File "/azure-functions-host/workers/python/3.10/LINUX/X64/azure_functions_worker/functions.py", line 251, in validate_function_params raise FunctionLoadError(

requirements.txt file

azure-functions==1.21.3

Where are you facing this problem?

Production Environment (explain below)

Additional Information

This error began occurring in my deployed Functions without any changes to code or dependencies. I have also seen this error in a handful of failed invocations of Functions that otherwise execute without error.

I replicated the error with the example Function found on the docs page for Azure Event Grid trigger for Azure Functions.

I can "fix" this error by removing the func.EventGridEvent type annotation from the main entrypoint function definition. A similar issue was raised several years ago.

bhagyshricompany commented 6 days ago

Hi @bmcandr Thanks for reporting We are investigating on this will update you the findings soon.please share the pex files( test_pex ) function with version for reference.

bmcandr commented 5 days ago

Sure. We actually use the Pants build system to produce our PEX. The error first appeared after we upgraded to v2.20 (which uses PEX v2.1.163).

Here is a PEX generated with Pants v2.19/PEX v2.1.148 that does not produce the error after zip-deploying as a Function App:

And here is a PEX produced with Pants v2.20/PEX v2.1.163 that DOES produce the error I reported:

You can view the contents of the entrypoint script, function.json, etc. files with

unzip -p test-pex-2.21.zip test_pex/__init__.py | cat

bmcandr commented 5 days ago

And here is an operation ID of a failed invocation in case it is helpful: 9ffa9cc2b7bfef52681158d54baad524.

This resulted in Executed 'Functions.test_pex' (Failed, Id=68381973-088e-4058-9c00-1d48fb4b4a91, Duration=11ms)