Skip to content

Commit 351dd93

Browse files
authored
Serialize False as a return value for orchestrators (#159)
* serialize falses * added test to prevent regression
1 parent 4d709be commit 351dd93

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

azure/durable_functions/models/OrchestratorState.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def to_json(self) -> Dict[str, Any]:
7777
json_dict = {}
7878
add_attrib(json_dict, self, '_is_done', 'isDone')
7979
self._add_actions(json_dict)
80-
if self._output:
80+
if not (self._output is None):
8181
json_dict['output'] = self._output
8282
if self._error:
8383
json_dict['error'] = self._error
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from tests.test_utils.ContextBuilder import ContextBuilder
2+
from .orchestrator_test_utils \
3+
import get_orchestration_state_result, assert_orchestration_state_equals, assert_valid_schema
4+
from azure.durable_functions.models.OrchestratorState import OrchestratorState
5+
6+
def base_expected_state(output=None) -> OrchestratorState:
7+
return OrchestratorState(is_done=False, actions=[], output=output)
8+
9+
def generator_function(context):
10+
return False
11+
12+
def test_serialization_of_False():
13+
"""Test that an orchestrator can return False."""
14+
15+
context_builder = ContextBuilder("serialize False")
16+
17+
result = get_orchestration_state_result(
18+
context_builder, generator_function)
19+
20+
expected_state = base_expected_state(output=False)
21+
22+
expected_state._is_done = True
23+
expected = expected_state.to_json()
24+
25+
# Since we're essentially testing the `to_json` functionality,
26+
# we explicitely ensure that the output is set
27+
expected["output"] = False
28+
29+
assert_valid_schema(result)
30+
assert_orchestration_state_equals(expected, result)

0 commit comments

Comments
 (0)