1- import dataclasses
21import uuid
32from datetime import datetime , timedelta
43from ipaddress import IPv4Address
109from temporalio .client import Client
1110from temporalio .contrib .pydantic .converter import pydantic_data_converter
1211from temporalio .worker import Worker
13- from temporalio .worker .workflow_sandbox import (
14- SandboxedWorkflowRunner ,
15- SandboxRestrictions ,
16- )
1712
1813
1914class MyPydanticModel (BaseModel ):
@@ -37,29 +32,6 @@ async def run(self, models: List[MyPydanticModel]) -> List[MyPydanticModel]:
3732 )
3833
3934
40- # Due to known issues with Pydantic's use of issubclass and our inability to
41- # override the check in sandbox, Pydantic will think datetime is actually date
42- # in the sandbox. At the expense of protecting against datetime.now() use in
43- # workflows, we're going to remove datetime module restrictions. See sdk-python
44- # README's discussion of known sandbox issues for more details.
45- def new_sandbox_runner () -> SandboxedWorkflowRunner :
46- # TODO(cretz): Use with_child_unrestricted when https://github.com/temporalio/sdk-python/issues/254
47- # is fixed and released
48- invalid_module_member_children = dict (
49- SandboxRestrictions .invalid_module_members_default .children
50- )
51- del invalid_module_member_children ["datetime" ]
52- return SandboxedWorkflowRunner (
53- restrictions = dataclasses .replace (
54- SandboxRestrictions .default ,
55- invalid_module_members = dataclasses .replace (
56- SandboxRestrictions .invalid_module_members_default ,
57- children = invalid_module_member_children ,
58- ),
59- )
60- )
61-
62-
6335async def test_workflow_with_pydantic_model (client : Client ):
6436 # Replace data converter in client
6537 new_config = client .config ()
@@ -83,7 +55,6 @@ async def test_workflow_with_pydantic_model(client: Client):
8355 task_queue = task_queue_name ,
8456 workflows = [MyWorkflow ],
8557 activities = [my_activity ],
86- workflow_runner = new_sandbox_runner (),
8758 ):
8859 result = await client .execute_workflow (
8960 MyWorkflow .run ,
0 commit comments