Skip to content

Commit a2eb8a9

Browse files
committed
Why is a restricted pathlib.Path accepted but not a restricted datetime?
1 parent b3f3662 commit a2eb8a9

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

temporalio/worker/workflow_sandbox/_restrictions.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from __future__ import annotations
88

99
import dataclasses
10-
import datetime
1110
import functools
1211
import inspect
1312
import logging
@@ -963,7 +962,6 @@ def _is_restrictable(v: Any) -> bool:
963962
str,
964963
bytes,
965964
bytearray,
966-
datetime.date, # e.g. datetime.datetime
967965
),
968966
)
969967

tests/contrib/pydantic/test_pydantic.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import dataclasses
2+
import pathlib
23
import uuid
34
from datetime import datetime
45

@@ -9,6 +10,11 @@
910
from temporalio.client import Client
1011
from temporalio.contrib.pydantic import pydantic_data_converter
1112
from temporalio.worker import Worker
13+
from temporalio.worker.workflow_sandbox._restrictions import (
14+
RestrictionContext,
15+
SandboxMatcher,
16+
_RestrictedProxy,
17+
)
1218
from tests.contrib.pydantic.models import (
1319
PydanticModels,
1420
PydanticModelWithStrictField,
@@ -324,3 +330,36 @@ async def test_validation_error(client: Client):
324330
task_queue=task_queue_name,
325331
result_type=tuple[int],
326332
)
333+
334+
335+
class RestrictedProxyFieldsModel(BaseModel):
336+
datetime_field: datetime
337+
path_field: pathlib.Path
338+
339+
340+
def test_model_instantiation_from_restricted_proxy_values():
341+
restricted_path_cls = _RestrictedProxy(
342+
"Path",
343+
pathlib.Path,
344+
RestrictionContext(),
345+
SandboxMatcher(),
346+
)
347+
restricted_datetime_cls = _RestrictedProxy(
348+
"datetime",
349+
datetime,
350+
RestrictionContext(),
351+
SandboxMatcher(),
352+
)
353+
354+
restricted_path = restricted_path_cls("test/path")
355+
restricted_datetime = restricted_datetime_cls(2025, 1, 2, 3, 4, 5)
356+
357+
assert type(restricted_path) is _RestrictedProxy
358+
assert type(restricted_datetime) is _RestrictedProxy
359+
360+
p = RestrictedProxyFieldsModel(
361+
datetime_field=restricted_datetime, # type: ignore
362+
path_field=restricted_path, # type: ignore
363+
)
364+
assert p.datetime_field == restricted_datetime
365+
assert p.path_field == restricted_path

0 commit comments

Comments
 (0)