23
23
from nexusrpc .handler ._decorators import operation_handler
24
24
25
25
import temporalio .api
26
+ import temporalio .api .common .v1
26
27
import temporalio .api .enums .v1
28
+ import temporalio .api .history .v1
27
29
import temporalio .nexus ._operation_handlers
28
30
from temporalio import nexus , workflow
29
31
from temporalio .client import (
@@ -1113,11 +1115,12 @@ async def assert_handler_workflow_has_link_to_caller_workflow(
1113
1115
== temporalio .api .enums .v1 .EventType .EVENT_TYPE_WORKFLOW_EXECUTION_STARTED
1114
1116
)
1115
1117
)
1116
- if not len (wf_started_event .links ) == 1 :
1118
+ links = _get_links_from_workflow_execution_started_event (wf_started_event )
1119
+ if not len (links ) == 1 :
1117
1120
pytest .fail (
1118
- f"Expected 1 link on WorkflowExecutionStarted event, got { len (wf_started_event . links )} "
1121
+ f"Expected 1 link on WorkflowExecutionStarted event, got { len (links )} "
1119
1122
)
1120
- [link ] = wf_started_event . links
1123
+ [link ] = links
1121
1124
assert link .workflow_event .namespace == caller_wf_handle ._client .namespace
1122
1125
assert link .workflow_event .workflow_id == caller_wf_handle .id
1123
1126
assert link .workflow_event .run_id
@@ -1128,6 +1131,17 @@ async def assert_handler_workflow_has_link_to_caller_workflow(
1128
1131
)
1129
1132
1130
1133
1134
+ def _get_links_from_workflow_execution_started_event (
1135
+ event : temporalio .api .history .v1 .HistoryEvent ,
1136
+ ) -> list [temporalio .api .common .v1 .Link ]:
1137
+ [callback ] = event .workflow_execution_started_event_attributes .completion_callbacks
1138
+ if links := callback .links :
1139
+ assert not event .links , "Did not expect both callback.links and event.links"
1140
+ return list (links )
1141
+ else :
1142
+ return list (event .links )
1143
+
1144
+
1131
1145
# When request_cancel is True, the NexusOperationHandle in the workflow evolves
1132
1146
# through the following states:
1133
1147
# start_fut result_fut handle_task w/ fut_waiter (task._must_cancel)
0 commit comments