Skip to content

Commit dd00e1e

Browse files
committed
Merge branch 'dajusto/debug-utils' of https://github.com/Azure/azure-functions-durable-python into dajusto/debug-utils
2 parents d768222 + cca7223 commit dd00e1e

File tree

4 files changed

+33
-6
lines changed

4 files changed

+33
-6
lines changed

azure/durable_functions/models/Task.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def __init__(self, is_completed, is_faulted, action,
2626
self._id = id_
2727
self._exception = exc
2828
self._is_played = is_played
29+
self._is_yielded: bool = False
2930

3031
@property
3132
def is_completed(self) -> bool:

azure/durable_functions/models/TaskSet.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def __init__(self, is_completed, actions, result, is_faulted=False,
2525
self._timestamp: datetime = timestamp
2626
self._exception = exception
2727
self._is_played = is_played
28+
self._is_yielded: bool = False
2829

2930
@property
3031
def is_completed(self) -> bool:

azure/durable_functions/orchestrator.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,14 @@ def _add_to_actions(self, generation_state):
134134
# Do not add new tasks to action if continue_as_new was called
135135
if self.durable_context.will_continue_as_new:
136136
return
137-
if (isinstance(generation_state, Task)
138-
and hasattr(generation_state, "action")):
139-
self.durable_context.actions.append([generation_state.action])
140-
elif (isinstance(generation_state, TaskSet)
141-
and hasattr(generation_state, "actions")):
142-
self.durable_context.actions.append(generation_state.actions)
137+
if not generation_state._is_yielded:
138+
if (isinstance(generation_state, Task)
139+
and hasattr(generation_state, "action")):
140+
self.durable_context.actions.append([generation_state.action])
141+
elif (isinstance(generation_state, TaskSet)
142+
and hasattr(generation_state, "actions")):
143+
self.durable_context.actions.append(generation_state.actions)
144+
generation_state._is_yielded = True
143145

144146
def _update_timestamp(self):
145147
last_timestamp = self.durable_context.decision_started_event.timestamp

tests/orchestrator/test_sequential_orchestrator.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ def generator_function(context):
2121

2222
return outputs
2323

24+
def generator_function_duplicate_yield(context):
25+
task1 = context.call_activity("Hello", "Tokyo")
26+
yield task1
27+
yield task1
28+
29+
return ""
30+
2431
def generator_function_time_is_not_none(context):
2532
outputs = []
2633

@@ -385,3 +392,19 @@ def test_new_guid_orchestrator():
385392
# The two GUID lists should be the same
386393
assert outputs1 == outputs2
387394

395+
def test_duplicate_yields_do_not_add_duplicate_actions():
396+
"""Tests that yield'ing a Task twice does not double the task's actions"""
397+
context_builder = ContextBuilder('test_guid_orchestrator')
398+
add_hello_completed_events(context_builder, 0, "\"Hello Tokyo!\"")
399+
400+
result = get_orchestration_state_result(
401+
context_builder, generator_function_duplicate_yield)
402+
403+
expected_state = base_expected_state("")
404+
add_hello_action(expected_state, 'Tokyo')
405+
expected_state._is_done = True
406+
expected = expected_state.to_json()
407+
408+
assert_valid_schema(result)
409+
assert_orchestration_state_equals(expected, result)
410+

0 commit comments

Comments
 (0)