Skip to content

Commit 3e2500c

Browse files
authored
Do not wrap workflow-failure exceptions from converters in workflows (#882)
1 parent 8bb5935 commit 3e2500c

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

temporalio/worker/_workflow_instance.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1792,6 +1792,8 @@ def _convert_payloads(
17921792
# Don't wrap payload conversion errors that would fail the workflow
17931793
raise
17941794
except Exception as err:
1795+
if self._is_workflow_failure_exception(err):
1796+
raise
17951797
raise RuntimeError("Failed decoding arguments") from err
17961798

17971799
def _instantiate_workflow_object(self) -> Any:

tests/worker/test_workflow.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
)
3838
from urllib.request import urlopen
3939

40+
import pydantic
4041
from google.protobuf.timestamp_pb2 import Timestamp
4142
from typing_extensions import Literal, Protocol, runtime_checkable
4243

@@ -5194,6 +5195,30 @@ async def run_scenario(
51945195
)
51955196

51965197

5198+
class Foo(pydantic.BaseModel):
5199+
bar: str
5200+
5201+
5202+
@workflow.defn(failure_exception_types=[pydantic.ValidationError])
5203+
class FailOnBadPydanticInputWorkflow:
5204+
@workflow.run
5205+
async def run(self, params: Foo) -> None:
5206+
pass
5207+
5208+
5209+
async def test_workflow_fail_on_bad_pydantic_input(client: Client):
5210+
async with new_worker(client, FailOnBadPydanticInputWorkflow) as worker:
5211+
with pytest.raises(WorkflowFailureError) as err:
5212+
await client.execute_workflow(
5213+
"FailOnBadPydanticInputWorkflow",
5214+
{"bar": 123}, # This should fail validation
5215+
id=f"wf-{uuid.uuid4()}",
5216+
task_queue=worker.task_queue,
5217+
)
5218+
assert isinstance(err.value.cause, ApplicationError)
5219+
assert "1 validation error for Foo" in err.value.cause.message
5220+
5221+
51975222
@workflow.defn(failure_exception_types=[Exception])
51985223
class FailOnBadInputWorkflow:
51995224
@workflow.run
@@ -5211,7 +5236,7 @@ async def test_workflow_fail_on_bad_input(client: Client):
52115236
task_queue=worker.task_queue,
52125237
)
52135238
assert isinstance(err.value.cause, ApplicationError)
5214-
assert "Failed decoding arguments" in err.value.cause.message
5239+
assert "Expected value to be str, was <class 'int'>" in err.value.cause.message
52155240

52165241

52175242
@workflow.defn

0 commit comments

Comments
 (0)