From f6d7d5db9c9f834b14d4c5c0869b468c932abb60 Mon Sep 17 00:00:00 2001 From: hallvictoria Date: Tue, 6 Feb 2024 10:28:56 -0600 Subject: [PATCH 1/5] sample durableClient converter --- azure/functions/durable_functions.py | 52 ++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/azure/functions/durable_functions.py b/azure/functions/durable_functions.py index 16c4fc4c..83f5bef9 100644 --- a/azure/functions/durable_functions.py +++ b/azure/functions/durable_functions.py @@ -124,3 +124,55 @@ def encode(cls, obj: typing.Any, *, @classmethod def has_implicit_output(cls) -> bool: return True + + +# Durable Function Activity Trigger +class DurableClientConverter(meta.InConverter, + meta.OutConverter, + binding='durableClient'): + + @classmethod + def has_trigger_support(cls) -> bool: + return False + + @classmethod + def check_input_type_annotation(cls, pytype: type) -> bool: + return issubclass(pytype, (str, bytes)) + + @classmethod + def check_output_type_annotation(cls, pytype: type) -> bool: + return issubclass(pytype, (str, bytes, bytearray)) + + @classmethod + def encode(cls, obj: typing.Any, *, + expected_type: typing.Optional[type]) -> meta.Datum: + if isinstance(obj, str): + return meta.Datum(type='string', value=obj) + + elif isinstance(obj, (bytes, bytearray)): + return meta.Datum(type='bytes', value=bytes(obj)) + + else: + raise NotImplementedError + + @classmethod + def decode(cls, data: meta.Datum, *, trigger_metadata) -> typing.Any: + data_type = data.type + + if data_type == 'string': + result = data.value + elif data_type == 'bytes': + result = data.value + elif data_type == 'json': + result = data.value + else: + raise ValueError( + f'unexpected type of data received for the "generic" binding ' + f': {data_type!r}' + ) + + return result + + @classmethod + def has_implicit_output(cls, bind_name: typing.Optional[str]) -> bool: + return False \ No newline at end of file From 3b9ea50fcf631a8e3fe5317100226363f98fa769 Mon Sep 17 00:00:00 2001 From: hallvictoria Date: Mon, 12 Feb 2024 13:46:51 -0600 Subject: [PATCH 2/5] dc converter & test --- azure/functions/durable_functions.py | 8 ++++---- tests/test_durable_functions.py | 8 +++++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/azure/functions/durable_functions.py b/azure/functions/durable_functions.py index 83f5bef9..332cafef 100644 --- a/azure/functions/durable_functions.py +++ b/azure/functions/durable_functions.py @@ -128,8 +128,8 @@ def has_implicit_output(cls) -> bool: # Durable Function Activity Trigger class DurableClientConverter(meta.InConverter, - meta.OutConverter, - binding='durableClient'): + meta.OutConverter, + binding='durableClient'): @classmethod def has_trigger_support(cls) -> bool: @@ -174,5 +174,5 @@ def decode(cls, data: meta.Datum, *, trigger_metadata) -> typing.Any: return result @classmethod - def has_implicit_output(cls, bind_name: typing.Optional[str]) -> bool: - return False \ No newline at end of file + def has_implicit_output(cls) -> bool: + return False diff --git a/tests/test_durable_functions.py b/tests/test_durable_functions.py index 353492d8..d063c5c1 100644 --- a/tests/test_durable_functions.py +++ b/tests/test_durable_functions.py @@ -7,7 +7,8 @@ from azure.functions.durable_functions import ( OrchestrationTriggerConverter, EnitityTriggerConverter, - ActivityTriggerConverter + ActivityTriggerConverter, + DurableClientConverter ) from azure.functions._durable_functions import ( OrchestrationContext, @@ -218,6 +219,11 @@ def test_enitity_trigger_check_output_type_annotation(self): EnitityTriggerConverter.check_output_type_annotation(pytype=None) ) + def test_durable_client_check_output_type_annotation(self): + self.assertFalse( + DurableClientConverter.check_output_type_annotation(pytype=None) + ) + def test_activity_trigger_converter_decode_no_implementation_exception( self): is_exception_raised = False From b43f031f8c37fe744bbd95c280758d64fe12be4d Mon Sep 17 00:00:00 2001 From: hallvictoria Date: Mon, 12 Feb 2024 13:52:15 -0600 Subject: [PATCH 3/5] lint --- tests/test_durable_functions.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/test_durable_functions.py b/tests/test_durable_functions.py index d063c5c1..f8382862 100644 --- a/tests/test_durable_functions.py +++ b/tests/test_durable_functions.py @@ -214,16 +214,16 @@ def test_activity_trigger_has_implicit_return(self): ActivityTriggerConverter.has_implicit_output() ) + def test_durable_client_no_implicit_return(self): + self.assertFalse( + DurableClientConverter.has_implicit_output() + ) + def test_enitity_trigger_check_output_type_annotation(self): self.assertTrue( EnitityTriggerConverter.check_output_type_annotation(pytype=None) ) - def test_durable_client_check_output_type_annotation(self): - self.assertFalse( - DurableClientConverter.check_output_type_annotation(pytype=None) - ) - def test_activity_trigger_converter_decode_no_implementation_exception( self): is_exception_raised = False From cbf40328dd4a8fcd1ad49f82fcf73f859448698c Mon Sep 17 00:00:00 2001 From: hallvictoria Date: Mon, 12 Feb 2024 14:17:38 -0600 Subject: [PATCH 4/5] removed unnecessary funcs --- azure/functions/durable_functions.py | 43 ---------------------------- 1 file changed, 43 deletions(-) diff --git a/azure/functions/durable_functions.py b/azure/functions/durable_functions.py index 332cafef..f0795cc3 100644 --- a/azure/functions/durable_functions.py +++ b/azure/functions/durable_functions.py @@ -130,49 +130,6 @@ def has_implicit_output(cls) -> bool: class DurableClientConverter(meta.InConverter, meta.OutConverter, binding='durableClient'): - - @classmethod - def has_trigger_support(cls) -> bool: - return False - - @classmethod - def check_input_type_annotation(cls, pytype: type) -> bool: - return issubclass(pytype, (str, bytes)) - - @classmethod - def check_output_type_annotation(cls, pytype: type) -> bool: - return issubclass(pytype, (str, bytes, bytearray)) - - @classmethod - def encode(cls, obj: typing.Any, *, - expected_type: typing.Optional[type]) -> meta.Datum: - if isinstance(obj, str): - return meta.Datum(type='string', value=obj) - - elif isinstance(obj, (bytes, bytearray)): - return meta.Datum(type='bytes', value=bytes(obj)) - - else: - raise NotImplementedError - - @classmethod - def decode(cls, data: meta.Datum, *, trigger_metadata) -> typing.Any: - data_type = data.type - - if data_type == 'string': - result = data.value - elif data_type == 'bytes': - result = data.value - elif data_type == 'json': - result = data.value - else: - raise ValueError( - f'unexpected type of data received for the "generic" binding ' - f': {data_type!r}' - ) - - return result - @classmethod def has_implicit_output(cls) -> bool: return False From d0fde1b8deca2a5bede056c01f87eef6c2381740 Mon Sep 17 00:00:00 2001 From: Victoria Hall Date: Wed, 6 Mar 2024 15:35:59 -0600 Subject: [PATCH 5/5] typo --- azure/functions/durable_functions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure/functions/durable_functions.py b/azure/functions/durable_functions.py index f0795cc3..a9cb88bf 100644 --- a/azure/functions/durable_functions.py +++ b/azure/functions/durable_functions.py @@ -126,7 +126,7 @@ def has_implicit_output(cls) -> bool: return True -# Durable Function Activity Trigger +# Durable Functions Durable Client Bindings class DurableClientConverter(meta.InConverter, meta.OutConverter, binding='durableClient'):