1717import temporalio .api .workflowservice .v1
1818import temporalio .common
1919import temporalio .converter
20- import temporalio .failure
20+ import temporalio .exceptions
2121import temporalio .workflow_service
2222from temporalio .workflow_service import RPCError , RPCStatusCode
2323
@@ -396,10 +396,8 @@ async def result(
396396 req .next_page_token = b""
397397 continue
398398 # Ignoring anything after the first response like TypeScript
399- if not complete_attr .result :
400- return cast (T , None )
401- results = await self ._client .data_converter .decode (
402- complete_attr .result .payloads
399+ results = await temporalio .converter .decode_payloads (
400+ complete_attr .result , self ._client .data_converter
403401 )
404402 if not results :
405403 return cast (T , None )
@@ -414,38 +412,35 @@ async def result(
414412 req .next_page_token = b""
415413 continue
416414 raise WorkflowFailureError (
417- cause = await temporalio .failure . FailureError . from_proto (
415+ cause = await temporalio .exceptions . failure_to_error (
418416 fail_attr .failure , self ._client .data_converter
419- )
417+ ),
420418 )
421419 elif event .HasField ("workflow_execution_canceled_event_attributes" ):
422420 cancel_attr = event .workflow_execution_canceled_event_attributes
423- details = []
424- if cancel_attr .details and cancel_attr .details .payloads :
425- details = await self ._client .data_converter .decode (
426- cancel_attr .details .payloads
427- )
428421 raise WorkflowFailureError (
429- cause = temporalio .failure . FailureError (
422+ cause = temporalio .exceptions . CancelledError (
430423 "Workflow cancelled" ,
431- temporalio .failure .CancelledFailure (* details ),
424+ * (
425+ await temporalio .converter .decode_payloads (
426+ cancel_attr .details .payloads ,
427+ self ._client .data_converter ,
428+ )
429+ ),
432430 )
433431 )
434432 elif event .HasField ("workflow_execution_terminated_event_attributes" ):
435433 term_attr = event .workflow_execution_terminated_event_attributes
436- details = []
437- if term_attr .details and term_attr .details .payloads :
438- details = await self ._client .data_converter .decode (
439- term_attr .details .payloads
440- )
441434 raise WorkflowFailureError (
442- cause = temporalio .failure . FailureError (
435+ cause = temporalio .exceptions . TerminatedError (
443436 term_attr .reason or "Workflow terminated" ,
444- temporalio .failure .TerminatedFailure (
445- * details ,
446- reason = term_attr .reason or None ,
437+ * (
438+ await temporalio .converter .decode_payloads (
439+ term_attr .details .payloads ,
440+ self ._client .data_converter ,
441+ )
447442 ),
448- )
443+ ),
449444 )
450445 elif event .HasField ("workflow_execution_timed_out_event_attributes" ):
451446 time_attr = event .workflow_execution_timed_out_event_attributes
@@ -455,12 +450,10 @@ async def result(
455450 req .next_page_token = b""
456451 continue
457452 raise WorkflowFailureError (
458- cause = temporalio .failure . FailureError (
453+ cause = temporalio .exceptions . TimeoutError (
459454 "Workflow timed out" ,
460- temporalio .failure .TimeoutFailure (
461- temporalio .failure .TimeoutType .START_TO_CLOSE
462- ),
463- )
455+ type = temporalio .exceptions .TimeoutType .START_TO_CLOSE ,
456+ ),
464457 )
465458 elif event .HasField ("workflow_execution_continued_as_new_event_attributes" ):
466459 cont_attr = event .workflow_execution_continued_as_new_event_attributes
@@ -479,7 +472,7 @@ async def cancel(
479472 self ,
480473 * ,
481474 run_id : Optional [str ] = SELF_RUN_ID ,
482- first_execution_run_id : Optional [None ] ,
475+ first_execution_run_id : Optional [str ] = None ,
483476 ) -> None :
484477 """Cancel the workflow.
485478
@@ -902,7 +895,7 @@ async def terminate_workflow(self, input: TerminateWorkflowInput) -> None:
902895class WorkflowFailureError (Exception ):
903896 """Error that occurs when a workflow is unsuccessful."""
904897
905- def __init__ (self , * , cause : temporalio .failure .FailureError ) -> None :
898+ def __init__ (self , * , cause : temporalio .exceptions .FailureError ) -> None :
906899 """Create workflow failure error."""
907900 super ().__init__ ("Workflow execution failed" )
908901 # TODO(cretz): Confirm setting this __cause__ is acceptable
@@ -917,6 +910,10 @@ def __init__(self, new_execution_run_id: str) -> None:
917910 super ().__init__ ("Workflow continued as new" )
918911 self ._new_execution_run_id = new_execution_run_id
919912
913+ @property
914+ def new_execution_run_id (self ) -> str :
915+ return self ._new_execution_run_id
916+
920917
921918class WorkflowQueryRejectedError (Exception ):
922919 """Error that occurs when a query was rejected."""
0 commit comments