Skip to content

Commit 42abf89

Browse files
committed
support for returning list
1 parent 3710fbd commit 42abf89

File tree

6 files changed

+56
-3
lines changed

6 files changed

+56
-3
lines changed

azure_functions_worker/bindings/datumdef.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,14 @@ def datum_as_proto(datum: Datum) -> protos.TypedData:
199199
enable_content_negotiation=False,
200200
body=datum_as_proto(datum.value['body']),
201201
))
202+
elif datum.type is None:
203+
return None
202204
elif datum.type == 'dict':
203205
# TypedData doesn't support dict, so we return it as json
204206
return protos.TypedData(json=json.dumps(datum.value))
207+
elif datum.type == 'list':
208+
# TypedData doesn't support list, so we return it as json
209+
return protos.TypedData(json=json.dumps(datum.value))
205210
elif datum.type == 'http_response':
206211
return protos.TypedData(http=protos.RpcHttp(
207212
status_code=str(datum.value.status_code),
@@ -211,10 +216,9 @@ def datum_as_proto(datum: Datum) -> protos.TypedData:
211216
},
212217
cookies=parse_to_rpc_http_cookie_list(None),
213218
enable_content_negotiation=False,
214-
body=datum_as_proto(Datum(type="string", value=datum.value.get_body())),
219+
body=datum_as_proto(Datum(type="string",
220+
value=datum.value.get_body())),
215221
))
216-
elif datum.type is None:
217-
return None
218222
else:
219223
raise NotImplementedError(
220224
'unexpected Datum type: {!r}'.format(datum.type)

azure_functions_worker/bindings/generic.py

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ def encode(cls, obj: Any, *,
3232
return datumdef.Datum(type=None, value=obj)
3333
elif isinstance(obj, dict):
3434
return datumdef.Datum(type='dict', value=obj)
35+
elif isinstance(obj, list):
36+
return datumdef.Datum(type='list', value=obj)
3537
else:
3638
# This isn't a common case so we do it last
3739
from azure.functions import HttpResponse

tests/endtoend/generic_functions/generic_functions_stein/function_app.py

+14
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,17 @@ def return_bytes(mytimer: func.TimerRequest, testEntity):
8686
def return_dict(mytimer: func.TimerRequest, testEntity):
8787
logging.info("Return dict")
8888
return {"hello": "world"}
89+
90+
91+
@app.function_name(name="return_list")
92+
@app.schedule(schedule="*/1 * * * * *", arg_name="mytimer",
93+
run_on_startup=False,
94+
use_monitor=False)
95+
@app.generic_input_binding(
96+
arg_name="testEntity",
97+
type="table",
98+
connection="AzureWebJobsStorage",
99+
table_name="EventHubBatchTest")
100+
def return_list(mytimer: func.TimerRequest, testEntity):
101+
logging.info("Return list")
102+
return [1, 2, 3]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"scriptFile": "main.py",
3+
"bindings": [
4+
{
5+
"name": "mytimer",
6+
"type": "timerTrigger",
7+
"direction": "in",
8+
"schedule": "*/1 * * * * *",
9+
"runOnStartup": false
10+
},
11+
{
12+
"direction": "in",
13+
"type": "table",
14+
"name": "testEntity",
15+
"partitionKey": "test",
16+
"rowKey": "WillBePopulatedWithGuid",
17+
"tableName": "BindingTestTable",
18+
"connection": "AzureWebJobsStorage"
19+
}
20+
]
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
import logging
5+
6+
import azure.functions as func
7+
8+
9+
def main(mytimer: func.TimerRequest, testEntity):
10+
logging.info("Return list")
11+
return [1, 2, 3]

tests/endtoend/test_generic_functions.py

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def check_log_return_types(self, host_out: typing.List[str]):
5959
self.assertIn("Return string", host_out)
6060
self.assertIn("Return bytes", host_out)
6161
self.assertIn("Return dict", host_out)
62+
self.assertIn("Return list", host_out)
6263

6364
# Checks for failed executions
6465
errors_found = False

0 commit comments

Comments
 (0)