Skip to content

Commit 1af52e4

Browse files
committed
Emit unfinished handler warnings separately for cancellation
1 parent 4094e72 commit 1af52e4

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

temporalio/worker/_workflow_instance.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -429,15 +429,20 @@ def activate(
429429
f"Failed converting activation exception: {inner_err}"
430430
)
431431

432-
def is_completion(command):
432+
def is_non_cancellation_completion(command):
433433
return (
434434
command.HasField("complete_workflow_execution")
435435
or command.HasField("continue_as_new_workflow_execution")
436436
or command.HasField("fail_workflow_execution")
437-
or command.HasField("cancel_workflow_execution")
438437
)
439438

440-
if any(map(is_completion, self._current_completion.successful.commands)):
439+
# We do also warn in the case of workflow cancellation, but this is done
440+
# when handling the workflow cancellation, since we also cancel update
441+
# handlers at that time.
442+
if any(
443+
is_non_cancellation_completion(c)
444+
for c in self._current_completion.successful.commands
445+
):
441446
self._warn_if_unfinished_handlers()
442447

443448
return self._current_completion
@@ -1851,6 +1856,7 @@ async def _run_top_level_workflow_function(self, coro: Awaitable[None]) -> None:
18511856
err
18521857
):
18531858
self._add_command().cancel_workflow_execution.SetInParent()
1859+
self._warn_if_unfinished_handlers()
18541860
# Cancel update tasks, so that the update caller receives an
18551861
# update failed error. We do not currently cancel signal tasks
18561862
# since (a) doing so would require a workflow flag and (b) the

tests/worker/test_workflow.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -5584,9 +5584,16 @@ class _UnfinishedHandlersOnWorkflowTerminationTest:
55845584
async def test_warning_is_issued_on_exit_with_unfinished_handler(
55855585
self,
55865586
):
5587-
assert await self._run_workflow_and_get_warning() == (
5588-
self.handler_waiting == "-no-wait-all-handlers-finish-"
5589-
)
5587+
warning_emitted = await self._run_workflow_and_get_warning()
5588+
if self.workflow_termination_type == "-cancellation-":
5589+
# All paths through this test for which the workflow is cencalled result
5590+
# in the warning being emitted.
5591+
assert warning_emitted
5592+
else:
5593+
# Otherwise, the warning is emitted iff the workflow does not wait for handlers to finish.
5594+
assert warning_emitted == (
5595+
self.handler_waiting == "-no-wait-all-handlers-finish-"
5596+
)
55905597

55915598
async def _run_workflow_and_get_warning(self) -> bool:
55925599
workflow_id = f"wf-{uuid.uuid4()}"

0 commit comments

Comments
 (0)