@@ -44,13 +44,19 @@ def from_payload(self, payload: Payload, type_hint: Optional[Type] = None) -> An
4444 data = json .loads (payload .data .decode ())
4545 if type_hint and typing .get_origin (type_hint ) is list :
4646 assert isinstance (data , list ), "Expected list"
47- [type_hint ] = typing .get_args (type_hint )
48- assert type_hint is not None , "Expected type hint"
49- assert issubclass (type_hint , BaseModel ), "Expected BaseModel"
47+ [model ] = typing .get_args (type_hint )
48+ assert model is not None , "Expected type hint"
49+ assert issubclass (model , BaseModel ), "Expected BaseModel"
5050 if temporalio .workflow .unsafe .in_sandbox ():
51- type_hint = _unwrap_restricted_fields (type_hint )
52-
53- return [self ._from_dict (d , type_hint ) for d in data ]
51+ model = create_model (
52+ model .__name__ ,
53+ ** { # type: ignore
54+ name : (RestrictionContext .unwrap_if_proxied (f .annotation ), f )
55+ for name , f in model .model_fields .items ()
56+ },
57+ )
58+
59+ return [self ._from_dict (d , model ) for d in data ]
5460 return self ._from_dict (data , type_hint )
5561
5662 def _from_dict (self , data : dict , type_hint : Optional [Type ]) -> Any :
@@ -81,13 +87,3 @@ def __init__(self) -> None:
8187 payload_converter_class = PydanticPayloadConverter
8288)
8389"""Data converter using Pydantic JSON conversion."""
84-
85-
86- def _unwrap_restricted_fields (
87- model : Type [BaseModel ],
88- ) -> Type [BaseModel ]:
89- fields = {
90- name : (RestrictionContext .unwrap_if_proxied (f .annotation ), f )
91- for name , f in model .model_fields .items ()
92- }
93- return create_model (model .__name__ , ** fields ) # type: ignore
0 commit comments