Skip to content

Commit 4b6b7f7

Browse files
committed
Use v2 API to_jsonable_python
1 parent 3ac2a29 commit 4b6b7f7

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

temporalio/contrib/pydantic.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
)
2121

2222
import pydantic
23-
from pydantic.json import pydantic_encoder
2423

2524
import temporalio.workflow
2625
from temporalio.api.common.v1 import Payload
@@ -33,6 +32,11 @@
3332
)
3433
from temporalio.worker.workflow_sandbox._restrictions import RestrictionContext
3534

35+
try:
36+
from pydantic_core import to_jsonable_python
37+
except ImportError:
38+
from pydantic.json import pydantic_encoder as to_jsonable_python
39+
3640

3741
class _PydanticModelTypeConverter(JSONTypeConverter):
3842
def to_typed_value(self, hint: Type, value: Any) -> Any:
@@ -90,7 +94,7 @@ def to_payload(self, value: Any) -> Optional[Payload]:
9094
return Payload(
9195
metadata={"encoding": self.encoding.encode()},
9296
data=json.dumps(
93-
value, separators=(",", ":"), sort_keys=True, default=pydantic_encoder
97+
value, separators=(",", ":"), sort_keys=True, default=to_jsonable_python
9498
).encode(),
9599
)
96100

0 commit comments

Comments
 (0)