@@ -420,7 +420,7 @@ def activate(
420420 # We want some errors during activation, like those that can happen
421421 # during payload conversion, to be able to fail the workflow not the
422422 # task
423- if self ._is_workflow_failure_exception (err ):
423+ if self .workflow_is_failure_exception (err ):
424424 try :
425425 self ._set_workflow_failure (err )
426426 except Exception as inner_err :
@@ -635,7 +635,7 @@ async def run_update() -> None:
635635 # Validation failures are always update failures. We reuse
636636 # workflow failure logic to decide task failure vs update
637637 # failure after validation.
638- if not past_validation or self ._is_workflow_failure_exception (err ):
638+ if not past_validation or self .workflow_is_failure_exception (err ):
639639 if command is None :
640640 command = self ._add_command ()
641641 command .update_response .protocol_instance_id = (
@@ -1692,6 +1692,23 @@ def workflow_set_current_details(self, details: str):
16921692 self ._assert_not_read_only ("set current details" )
16931693 self ._current_details = details
16941694
1695+ def workflow_is_failure_exception (self , err : BaseException ) -> bool :
1696+ # An exception is a failure instead of a task fail if it's already a
1697+ # failure error or if it is a timeout error or if it is an instance of
1698+ # any of the failure types in the worker or workflow-level setting
1699+ wf_failure_exception_types = self ._defn .failure_exception_types
1700+ if self ._dynamic_failure_exception_types is not None :
1701+ wf_failure_exception_types = self ._dynamic_failure_exception_types
1702+ return (
1703+ isinstance (err , temporalio .exceptions .FailureError )
1704+ or isinstance (err , asyncio .TimeoutError )
1705+ or any (isinstance (err , typ ) for typ in wf_failure_exception_types )
1706+ or any (
1707+ isinstance (err , typ )
1708+ for typ in self ._worker_level_failure_exception_types
1709+ )
1710+ )
1711+
16951712 def workflow_has_last_completion_result (self ) -> bool :
16961713 return len (self ._last_completion_result .payloads ) > 0
16971714
@@ -1976,7 +1993,7 @@ def _convert_payloads(
19761993 # Don't wrap payload conversion errors that would fail the workflow
19771994 raise
19781995 except Exception as err :
1979- if self ._is_workflow_failure_exception (err ):
1996+ if self .workflow_is_failure_exception (err ):
19801997 raise
19811998 raise RuntimeError ("Failed decoding arguments" ) from err
19821999
@@ -2019,23 +2036,6 @@ def _instantiate_workflow_object(self) -> Any:
20192036
20202037 return workflow_instance
20212038
2022- def _is_workflow_failure_exception (self , err : BaseException ) -> bool :
2023- # An exception is a failure instead of a task fail if it's already a
2024- # failure error or if it is a timeout error or if it is an instance of
2025- # any of the failure types in the worker or workflow-level setting
2026- wf_failure_exception_types = self ._defn .failure_exception_types
2027- if self ._dynamic_failure_exception_types is not None :
2028- wf_failure_exception_types = self ._dynamic_failure_exception_types
2029- return (
2030- isinstance (err , temporalio .exceptions .FailureError )
2031- or isinstance (err , asyncio .TimeoutError )
2032- or any (isinstance (err , typ ) for typ in wf_failure_exception_types )
2033- or any (
2034- isinstance (err , typ )
2035- for typ in self ._worker_level_failure_exception_types
2036- )
2037- )
2038-
20392039 def _warn_if_unfinished_handlers (self ) -> None :
20402040 def warnable (handler_executions : Iterable [HandlerExecution ]):
20412041 return [
@@ -2229,7 +2229,7 @@ async def _run_top_level_workflow_function(self, coro: Awaitable[None]) -> None:
22292229 err
22302230 ):
22312231 self ._add_command ().cancel_workflow_execution .SetInParent ()
2232- elif self ._is_workflow_failure_exception (err ):
2232+ elif self .workflow_is_failure_exception (err ):
22332233 # All other failure errors fail the workflow
22342234 self ._set_workflow_failure (err )
22352235 else :
0 commit comments