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