Azure / azure-functions-python-worker

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

fix: allow returning none for generic bindings #1482

Closed hallvictoria closed 2 months ago

hallvictoria commented 2 months ago

Description

Currently, when a function is triggered, the worker expects a request body with the trigger. However, in the case of generic binding types like the Dapr Cron binding trigger, no data is sent with the trigger request. This causes the worker to crash with an exception AttributeError: 'NoneType' object has no attribute 'type'. This fix enables triggers to execute successfully even if the trigger calls the app without any request body.

As per 1391, implicit output is enabled for generic types. Therefore, function apps with generic bindings that are also returning None will face an error TypeError: unable to encode outgoing TypedData: unsupported type "<class 'azure_functions_worker.bindings.generic.GenericBinding'>" for Python type "NoneType". This changes the worker to allow this scenario.

Fixes https://github.com/Azure/azure-functions-python-worker/issues/1316 Fixes https://github.com/Azure/azure-functions-python-worker/issues/1479


PR information

Quality of Code and Contribution Guidelines