Skip to content

fix: allow returning none for generic bindings #1379

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
daa85d2
allow nill data for generic bindings
hallvictoria Dec 11, 2023
89c7835
tests
hallvictoria Dec 11, 2023
b097d14
lint
hallvictoria Dec 11, 2023
42b94c6
Merge branch 'dev' into hallvictoria/allow-nill-data
hallvictoria Dec 11, 2023
8fab3ed
Merge branch 'dev' of https://github.com/Azure/azure-functions-python…
hallvictoria Jan 11, 2024
3d7ae9d
Merge branch 'hallvictoria/allow-nill-data' of https://github.com/Azu…
hallvictoria Jan 11, 2024
f714ea3
added comment
hallvictoria Jan 11, 2024
87aac19
Merge branch 'dev' into hallvictoria/allow-nill-data
hallvictoria Jan 25, 2024
dbe218e
Merge branch 'dev' into hallvictoria/allow-nill-data
hallvictoria Jan 26, 2024
485e138
Merge branch 'dev' into hallvictoria/allow-nill-data
vrdmr Jan 31, 2024
886f0a2
Merge branch 'dev' into hallvictoria/allow-nill-data
hallvictoria Mar 1, 2024
dff0911
Merge branch 'dev' into hallvictoria/allow-nill-data
hallvictoria Mar 5, 2024
d88763a
Merge branch 'dev' into hallvictoria/allow-nill-data
gavin-aguiar Mar 26, 2024
b9d6d31
compatible with generic implicit output
Mar 27, 2024
66da8e2
removed if cond
hallvictoria Mar 28, 2024
3fd84f5
revert return none supp
hallvictoria Mar 29, 2024
8cad4fd
Merge branch 'dev' into hallvictoria/allow-nill-data
hallvictoria Mar 29, 2024
3baa53b
Merge branch 'dev' into hallvictoria/allow-nill-data
hallvictoria Apr 2, 2024
40c105b
added back support for returning None
hallvictoria Apr 2, 2024
ca87969
Merge branch 'dev' into hallvictoria/allow-nill-data
hallvictoria Apr 18, 2024
810f18d
e2e test with generic bind and return none
hallvictoria Apr 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions azure_functions_worker/bindings/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ def encode(cls, obj: Any, *,

@classmethod
def decode(cls, data: datumdef.Datum, *, trigger_metadata) -> typing.Any:
# Enabling support for Dapr bindings
# https://github.com/Azure/azure-functions-python-worker/issues/1316
if data is None:
return None
data_type = data.type

if data_type == 'string':
Expand Down
11 changes: 11 additions & 0 deletions tests/unittests/generic_functions/foobar_nil_data/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"scriptFile": "main.py",
"bindings": [
{
"type": "generic",
"name": "input",
"direction": "in"
}
]
}

7 changes: 7 additions & 0 deletions tests/unittests/generic_functions/foobar_nil_data/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
import logging


def main(input) -> None:
logging.info("Hello World")
25 changes: 25 additions & 0 deletions tests/unittests/test_mock_generic_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,28 @@ async def test_mock_generic_implicit_output_exemption(self):
# For the Durable Functions durableClient case
self.assertEqual(r.response.result.status,
protos.StatusResult.Failure)

async def test_mock_generic_as_nil_data(self):
async with testutils.start_mockhost(
script_root=self.generic_funcs_dir) as host:

await host.init_worker("4.17.1")
func_id, r = await host.load_function('foobar_nil_data')

self.assertEqual(r.response.function_id, func_id)
self.assertEqual(r.response.result.status,
protos.StatusResult.Success)

_, r = await host.invoke_function(
'foobar_nil_data', [
protos.ParameterBinding(
name='input',
data=protos.TypedData()
)
]
)
self.assertEqual(r.response.result.status,
protos.StatusResult.Success)
self.assertEqual(
r.response.return_value,
protos.TypedData())
Loading