Azure / azure-functions-python-worker

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

Enabled implicit output for generic bindings #1391

Closed hallvictoria closed 4 months ago

hallvictoria commented 6 months ago

Description

Enables implicit output for generic types. This addresses an ask from the Logic Apps team for generic type bindings to have implicit return.

In implementing this, two main errors occurred:

  1. Durable functions started failing with "FunctionLoadError: cannot load the DurableFunctionsHttpStart1 function: Python return annotation "HttpResponse" does not match binding type "durableClient""

    • Cause: durableClient is a generic type and implicit output should be False
    • Fix: durableClient has its own converter class in the python sdk, so it is no longer a generic type. We h;ave a special case for this type in the worker to maintain backwards compatibility
  2. get_eventhub_batch_triggered failed with "TypeError: unable to encode outgoing TypedData: unsupported type "<class 'azure_functions_worker.bindings.generic.GenericBinding'>" for Python type "HttpResponse""

    • Cause: functions now can have both explicit and implicit output set to true. Previously, we set the function's return type to be the type of the binding that either is called $return or has implicit output set to true. In the case where there's a generic binding (implicit output = true) and $return in the same function, return type gets overwritten, and it depends on the order in which the bindings are processed to see what the final return type is set to.
    • Fix: prioritize the return type associated with $return, if that is present.
    • Case 1: $return processed before generic type -The boolean will be set to true and prevent the return type from later being overwritten
    • Case 2: generic type processed before $return -The $return return type will overwrite the implicit output binding return type
    • Case 3: no $return -The return type will be set to that of the implicit output binding

Fixes #


PR information

Quality of Code and Contribution Guidelines

codecov[bot] commented 6 months ago

Codecov Report

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

Project coverage is 85.61%. Comparing base (2e91fa1) to head (466ee73).

Files Patch % Lines
azure_functions_worker/bindings/meta.py 66.66% 0 Missing and 1 partial :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## dev #1391 +/- ## ========================================== + Coverage 85.19% 85.61% +0.42% ========================================== Files 35 35 Lines 1965 1974 +9 Branches 370 374 +4 ========================================== + Hits 1674 1690 +16 + Misses 217 213 -4 + Partials 74 71 -3 ``` | [Flag](https://app.codecov.io/gh/Azure/azure-functions-python-worker/pull/1391/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/1391/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Azure) | `85.56% <93.33%> (+0.42%)` | :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.

YunchuWang commented 5 months ago

/profile