Skip to content

Commit f2ee3ca

Browse files
committed
Failing test
1 parent 53b8c33 commit f2ee3ca

File tree

2 files changed

+47
-7
lines changed

2 files changed

+47
-7
lines changed

tests/contrib/pydantic/test_pydantic.py

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
import uuid
33
from datetime import datetime
44

5+
import pytest
56
from pydantic import BaseModel
67

78
from temporalio.client import Client
89
from temporalio.contrib.pydantic import pydantic_data_converter
910
from temporalio.worker import Worker
1011
from tests.contrib.pydantic.models import (
12+
PydanticModels,
1113
PydanticModelWithStrictField,
1214
make_dataclass_objects,
1315
make_list_of_pydantic_objects,
@@ -18,6 +20,7 @@
1820
ComplexCustomUnionTypeWorkflow,
1921
DatetimeUsageWorkflow,
2022
InstantiateModelsWorkflow,
23+
NoTypeAnnotationsWorkflow,
2124
PydanticModelUsageWorkflow,
2225
PydanticModelWithStrictFieldWorkflow,
2326
RoundTripMiscObjectsWorkflow,
@@ -51,7 +54,8 @@ async def test_instantiation_inside_sandbox(client: Client):
5154
)
5255

5356

54-
async def test_round_trip_pydantic_objects(client: Client):
57+
@pytest.mark.parametrize("typed", [True, False])
58+
async def test_round_trip_pydantic_objects(client: Client, typed: bool):
5559
new_config = client.config()
5660
new_config["data_converter"] = pydantic_data_converter
5761
client = Client(**new_config)
@@ -65,12 +69,22 @@ async def test_round_trip_pydantic_objects(client: Client):
6569
workflows=[RoundTripPydanticObjectsWorkflow],
6670
activities=[pydantic_objects_activity],
6771
):
68-
returned_objects = await client.execute_workflow(
69-
RoundTripPydanticObjectsWorkflow.run,
70-
orig_objects,
71-
id=str(uuid.uuid4()),
72-
task_queue=task_queue_name,
73-
)
72+
if typed:
73+
returned_objects = await client.execute_workflow(
74+
RoundTripPydanticObjectsWorkflow.run,
75+
orig_objects,
76+
id=str(uuid.uuid4()),
77+
task_queue=task_queue_name,
78+
)
79+
else:
80+
returned_objects = await client.execute_workflow(
81+
"RoundTripPydanticObjectsWorkflow",
82+
orig_objects,
83+
id=str(uuid.uuid4()),
84+
task_queue=task_queue_name,
85+
result_type=list[PydanticModels],
86+
)
87+
7488
assert returned_objects == orig_objects
7589
for o in returned_objects:
7690
o._check_instance()
@@ -269,3 +283,22 @@ async def test_pydantic_model_with_strict_field_inside_sandbox(client: Client):
269283
task_queue=tq,
270284
)
271285
assert result == orig
286+
287+
288+
async def test_no_type_annotations(client: Client):
289+
new_config = client.config()
290+
new_config["data_converter"] = pydantic_data_converter
291+
client = Client(**new_config)
292+
task_queue_name = str(uuid.uuid4())
293+
async with Worker(
294+
client,
295+
task_queue=task_queue_name,
296+
workflows=[NoTypeAnnotationsWorkflow],
297+
):
298+
result = await client.execute_workflow(
299+
"NoTypeAnnotationsWorkflow",
300+
(7,),
301+
id=str(uuid.uuid4()),
302+
task_queue=task_queue_name,
303+
)
304+
assert result == [7]

tests/contrib/pydantic/workflows.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,10 @@ async def run(
166166
self, obj: PydanticModelWithStrictField
167167
) -> PydanticModelWithStrictField:
168168
return _test_pydantic_model_with_strict_field(obj)
169+
170+
171+
@workflow.defn
172+
class NoTypeAnnotationsWorkflow:
173+
@workflow.run
174+
async def run(self, arg):
175+
return arg

0 commit comments

Comments
 (0)