37
37
)
38
38
from urllib .request import urlopen
39
39
40
+ import pydantic
40
41
from google .protobuf .timestamp_pb2 import Timestamp
41
42
from typing_extensions import Literal , Protocol , runtime_checkable
42
43
@@ -5194,6 +5195,30 @@ async def run_scenario(
5194
5195
)
5195
5196
5196
5197
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
+
5197
5222
@workflow .defn (failure_exception_types = [Exception ])
5198
5223
class FailOnBadInputWorkflow :
5199
5224
@workflow .run
@@ -5211,7 +5236,7 @@ async def test_workflow_fail_on_bad_input(client: Client):
5211
5236
task_queue = worker .task_queue ,
5212
5237
)
5213
5238
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
5215
5240
5216
5241
5217
5242
@workflow .defn
0 commit comments