Skip to content

Commit 3600060

Browse files
committed
Lint + pylance
1 parent 5dfc57f commit 3600060

File tree

2 files changed

+30
-40
lines changed

2 files changed

+30
-40
lines changed

durabletask/worker.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,12 +1484,12 @@ def _build_rewind_result(
14841484
event_copy = pb.HistoryEvent()
14851485
event_copy.CopyFrom(event)
14861486
event_copy.executionStarted.orchestrationInstance.executionId.CopyFrom(
1487-
ph.get_string_value(new_execution_id))
1488-
if (rewind_event is not None
1489-
and rewind_event.HasField("parentExecutionId")
1490-
and rewind_event.parentExecutionId.value):
1491-
event_copy.executionStarted.parentInstance.orchestrationInstance.executionId.CopyFrom(
1492-
rewind_event.parentExecutionId)
1487+
ph.get_string_value_or_empty(new_execution_id))
1488+
if rewind_event is not None:
1489+
if rewind_event.HasField("parentExecutionId"):
1490+
if rewind_event.parentExecutionId.value:
1491+
event_copy.executionStarted.parentInstance.orchestrationInstance.executionId.CopyFrom(
1492+
rewind_event.parentExecutionId)
14931493
clean_history.append(event_copy)
14941494
continue
14951495

tests/durabletask/test_build_rewind_result.py

Lines changed: 24 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -420,26 +420,22 @@ def test_rewind_preserves_successful_sub_orchestration():
420420
clean = _get_clean_history(result)
421421

422422
# Sub-orch 1's created + completed should be present.
423-
assert any(
424-
e.HasField("subOrchestrationInstanceCreated")
425-
and e.subOrchestrationInstanceCreated.instanceId == "child-ok-id"
426-
for e in clean
427-
)
428-
assert any(
429-
e.HasField("subOrchestrationInstanceCompleted")
430-
and e.subOrchestrationInstanceCompleted.taskScheduledId == 1
431-
for e in clean
432-
)
423+
created_ids = [
424+
e.subOrchestrationInstanceCreated.instanceId
425+
for e in clean if e.HasField("subOrchestrationInstanceCreated")
426+
]
427+
assert "child-ok-id" in created_ids
428+
completed_sub_ids = [
429+
e.subOrchestrationInstanceCompleted.taskScheduledId
430+
for e in clean if e.HasField("subOrchestrationInstanceCompleted")
431+
]
432+
assert 1 in completed_sub_ids
433433
# Sub-orch 2's failed event should be removed.
434434
assert not any(
435435
e.HasField("subOrchestrationInstanceFailed") for e in clean
436436
)
437437
# Sub-orch 2's created event should be kept (for backend recursive rewind).
438-
assert any(
439-
e.HasField("subOrchestrationInstanceCreated")
440-
and e.subOrchestrationInstanceCreated.instanceId == "child-fail-id"
441-
for e in clean
442-
)
438+
assert "child-fail-id" in created_ids
443439

444440

445441
# ---------------------------------------------------------------------------
@@ -618,26 +614,22 @@ def test_rewind_mixed_activities_and_sub_orchestrations():
618614
assert not any(e.HasField("taskFailed") for e in clean)
619615

620616
# --- Successful sub-orch A preserved ---
621-
assert any(
622-
e.HasField("subOrchestrationInstanceCreated")
623-
and e.subOrchestrationInstanceCreated.instanceId == "child-ok-id"
624-
for e in clean
625-
)
626-
assert any(
627-
e.HasField("subOrchestrationInstanceCompleted")
628-
and e.subOrchestrationInstanceCompleted.taskScheduledId == 2
629-
for e in clean
630-
)
617+
created_ids = [
618+
e.subOrchestrationInstanceCreated.instanceId
619+
for e in clean if e.HasField("subOrchestrationInstanceCreated")
620+
]
621+
assert "child-ok-id" in created_ids
622+
completed_sub_ids = [
623+
e.subOrchestrationInstanceCompleted.taskScheduledId
624+
for e in clean if e.HasField("subOrchestrationInstanceCompleted")
625+
]
626+
assert 2 in completed_sub_ids
631627

632628
# --- Failed sub-orch B: failed event removed, created kept ---
633629
assert not any(
634630
e.HasField("subOrchestrationInstanceFailed") for e in clean
635631
)
636-
assert any(
637-
e.HasField("subOrchestrationInstanceCreated")
638-
and e.subOrchestrationInstanceCreated.instanceId == "child-fail-id"
639-
for e in clean
640-
)
632+
assert "child-fail-id" in created_ids
641633

642634
# --- executionCompleted removed ---
643635
assert not any(e.HasField("executionCompleted") for e in clean)
@@ -674,10 +666,8 @@ def test_rewind_does_not_mutate_original_events():
674666
TEST_INSTANCE_ID, "orch", old_events, new_events)
675667

676668
# The original executionStarted event should NOT be mutated.
677-
assert (
678-
es_event.executionStarted.orchestrationInstance.executionId.value
679-
== original_exec_id
680-
)
669+
actual = es_event.executionStarted.orchestrationInstance.executionId.value
670+
assert actual == original_exec_id
681671

682672

683673
def test_rewind_result_action_structure():

0 commit comments

Comments
 (0)