Azure / azure-functions-python-worker

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

fix: allow returning none for generic bindings #1379

Closed hallvictoria closed 5 months ago

hallvictoria commented 9 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

codecov[bot] commented 9 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 85.46%. Comparing base (7de7724) to head (dff0911). Report is 3 commits behind head on dev.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## dev #1379 +/- ## ========================================== + Coverage 85.44% 85.46% +0.01% ========================================== Files 35 35 Lines 1965 1967 +2 Branches 370 371 +1 ========================================== + Hits 1679 1681 +2 Misses 213 213 Partials 73 73 ``` | [Flag](https://app.codecov.io/gh/Azure/azure-functions-python-worker/pull/1379/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Azure) | Coverage Δ | | |---|---|---| | [unittests](https://app.codecov.io/gh/Azure/azure-functions-python-worker/pull/1379/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Azure) | `85.40% <100.00%> (+0.01%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Azure#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov-commenter commented 6 months ago

Codecov Report

Attention: Patch coverage is 75.00000% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 85.12%. Comparing base (330783f) to head (40c105b). Report is 5 commits behind head on dev.

:exclamation: Current head 40c105b differs from pull request most recent head ca87969. Consider uploading reports for the commit ca87969 to get more accurate results

Files Patch % Lines
azure_functions_worker/bindings/generic.py 66.66% 2 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## dev #1379 +/- ## ========================================== + Coverage 84.64% 85.12% +0.48% ========================================== Files 35 35 Lines 2052 2004 -48 Branches 387 381 -6 ========================================== - Hits 1737 1706 -31 + Misses 232 223 -9 + Partials 83 75 -8 ``` | [Flag](https://app.codecov.io/gh/Azure/azure-functions-python-worker/pull/1379/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Azure) | Coverage Δ | | |---|---|---| | [unittests](https://app.codecov.io/gh/Azure/azure-functions-python-worker/pull/1379/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Azure) | `85.07% <75.00%> (+0.47%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Azure#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.