Skip to content

Commit 46128cc

Browse files
author
Hanzhang Zeng (Roger)
committed
Added durable functions support by loosing return type checking
1 parent 9b3b422 commit 46128cc

File tree

5 files changed

+29
-7
lines changed

5 files changed

+29
-7
lines changed

azure_functions_worker/bindings/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from .context import Context
33
from .meta import check_input_type_annotation
44
from .meta import check_output_type_annotation
5+
from .meta import has_implicit_output
56
from .meta import is_trigger_binding
67
from .meta import from_incoming_proto, to_outgoing_proto
78
from .out import Out
@@ -11,5 +12,6 @@
1112
'Out', 'Context',
1213
'is_trigger_binding',
1314
'check_input_type_annotation', 'check_output_type_annotation',
15+
'has_implicit_output',
1416
'from_incoming_proto', 'to_outgoing_proto', 'TraceContext',
1517
)

azure_functions_worker/bindings/generic.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,7 @@ def decode(cls, data: datumdef.Datum, *, trigger_metadata) -> typing.Any:
4646
)
4747

4848
return result
49+
50+
@classmethod
51+
def has_implicit_output(cls) -> bool:
52+
return False

azure_functions_worker/bindings/meta.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
def get_binding_registry():
1111
func = sys.modules.get('azure.functions')
12+
1213
if func is not None:
1314
return func.get_binding_registry()
1415
else:
@@ -20,7 +21,6 @@ def get_binding(bind_name: str) -> object:
2021
registry = get_binding_registry()
2122
if registry is not None:
2223
binding = registry.get(bind_name)
23-
2424
if binding is None:
2525
binding = generic.GenericBinding
2626

@@ -32,16 +32,24 @@ def is_trigger_binding(bind_name: str) -> bool:
3232
return binding.has_trigger_support()
3333

3434

35-
def check_input_type_annotation(binding: str, pytype: type) -> bool:
36-
binding = get_binding(binding)
35+
def check_input_type_annotation(bind_name: str, pytype: type) -> bool:
36+
binding = get_binding(bind_name)
3737
return binding.check_input_type_annotation(pytype)
3838

3939

40-
def check_output_type_annotation(binding: str, pytype: type) -> bool:
41-
binding = get_binding(binding)
40+
def check_output_type_annotation(bind_name: str, pytype: type) -> bool:
41+
binding = get_binding(bind_name)
4242
return binding.check_output_type_annotation(pytype)
4343

4444

45+
def has_implicit_output(bind_name: str) -> bool:
46+
binding = get_binding(bind_name)
47+
48+
# If the binding does not have metaclass of meta.InConverter
49+
# The implicit_output does not exist
50+
return getattr(binding, 'has_implicit_output', lambda: False)()
51+
52+
4553
def from_incoming_proto(
4654
binding: str,
4755
val: protos.TypedData, *,

azure_functions_worker/functions.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ def add_function(self, function_id: str,
8282
assert return_binding_name is not None
8383

8484
has_return = True
85+
elif bindings.has_implicit_output(desc.type):
86+
# If the binding specify implicit output binding
87+
# (e.g. orchestrationTrigger, activityTrigger)
88+
# we should enable output even if $return is not specified
89+
has_return = True
90+
return_binding_name = f'{desc.type}_ret'
91+
bound_params[name] = desc
8592
else:
8693
bound_params[name] = desc
8794

@@ -180,7 +187,8 @@ def add_function(self, function_id: str,
180187
f'direction in function.json, but its annotation '
181188
f'is azure.functions.Out in Python')
182189

183-
if param_has_anno and param_py_type in (str, bytes):
190+
if param_has_anno and param_py_type in (str, bytes) and (
191+
not bindings.has_implicit_output(desc.type)):
184192
param_bind_type = 'generic'
185193
else:
186194
param_bind_type = desc.type

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ def run(self):
279279
],
280280
extras_require={
281281
'dev': [
282-
'azure-functions==1.1.0',
282+
'azure-functions==1.2.0b1',
283283
'flake8~=3.7.9',
284284
'mypy',
285285
'pytest',

0 commit comments

Comments
 (0)