|
18 | 18 | from typing_extensions import Concatenate |
19 | 19 |
|
20 | 20 | import temporalio.api.common.v1 |
| 21 | +import temporalio.api.workflowservice.v1 |
21 | 22 | import temporalio.client |
22 | 23 | import temporalio.common |
23 | 24 | from temporalio.nexus import _link_conversion |
@@ -142,25 +143,30 @@ def _get_workflow_event_links( |
142 | 143 | def _add_outbound_links( |
143 | 144 | self, workflow_handle: temporalio.client.WorkflowHandle[Any, Any] |
144 | 145 | ): |
| 146 | + # If links were not sent in StartWorkflowExecutionResponse then construct them. |
| 147 | + wf_event_links: list[temporalio.api.common.v1.Link.WorkflowEvent] = [] |
145 | 148 | try: |
146 | | - link = _link_conversion.workflow_event_to_nexus_link( |
147 | | - _link_conversion.workflow_handle_to_workflow_execution_started_event_link( |
148 | | - workflow_handle |
149 | | - ) |
| 149 | + if isinstance( |
| 150 | + workflow_handle._start_workflow_response, |
| 151 | + temporalio.api.workflowservice.v1.StartWorkflowExecutionResponse, |
| 152 | + ): |
| 153 | + if workflow_handle._start_workflow_response.HasField("link"): |
| 154 | + if link := workflow_handle._start_workflow_response.link: |
| 155 | + if link.HasField("workflow_event"): |
| 156 | + wf_event_links.append(link.workflow_event) |
| 157 | + if not wf_event_links: |
| 158 | + wf_event_links = [ |
| 159 | + _link_conversion.workflow_execution_started_event_link_from_workflow_handle( |
| 160 | + workflow_handle |
| 161 | + ) |
| 162 | + ] |
| 163 | + self.nexus_context.outbound_links.extend( |
| 164 | + _link_conversion.workflow_event_to_nexus_link(link) |
| 165 | + for link in wf_event_links |
150 | 166 | ) |
151 | 167 | except Exception as e: |
152 | 168 | logger.warning( |
153 | | - f"Failed to create WorkflowExecutionStarted event link for workflow {id}: {e}" |
154 | | - ) |
155 | | - else: |
156 | | - self.nexus_context.outbound_links.append( |
157 | | - # TODO(nexus-prerelease): Before, WorkflowRunOperation was generating an EventReference |
158 | | - # link to send back to the caller. Now, it checks if the server returned |
159 | | - # the link in the StartWorkflowExecutionResponse, and if so, send the link |
160 | | - # from the response to the caller. Fallback to generating the link for |
161 | | - # backwards compatibility. PR reference in Go SDK: |
162 | | - # https://github.com/temporalio/sdk-go/pull/1934 |
163 | | - link |
| 169 | + f"Failed to create WorkflowExecutionStarted event links for workflow {workflow_handle}: {e}" |
164 | 170 | ) |
165 | 171 | return workflow_handle |
166 | 172 |
|
|
0 commit comments