|
1 | 1 | import dataclasses
|
| 2 | +import pathlib |
2 | 3 | import uuid
|
3 | 4 | from datetime import datetime
|
4 | 5 |
|
|
9 | 10 | from temporalio.client import Client
|
10 | 11 | from temporalio.contrib.pydantic import pydantic_data_converter
|
11 | 12 | from temporalio.worker import Worker
|
| 13 | +from temporalio.worker.workflow_sandbox._restrictions import ( |
| 14 | + RestrictionContext, |
| 15 | + SandboxMatcher, |
| 16 | + _RestrictedProxy, |
| 17 | +) |
12 | 18 | from tests.contrib.pydantic.models import (
|
13 | 19 | PydanticModels,
|
14 | 20 | PydanticModelWithStrictField,
|
@@ -324,3 +330,36 @@ async def test_validation_error(client: Client):
|
324 | 330 | task_queue=task_queue_name,
|
325 | 331 | result_type=tuple[int],
|
326 | 332 | )
|
| 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