Skip to content

Commit 0d3fd0c

Browse files
committed
Warn pydantic users who are not using contrib.pydantic
1 parent 775e4ee commit 0d3fd0c

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

temporalio/converter.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import sys
1111
import traceback
1212
import uuid
13+
import warnings
1314
from abc import ABC, abstractmethod
1415
from dataclasses import dataclass
1516
from datetime import datetime
@@ -1523,15 +1524,19 @@ def value_to_type(
15231524
# the start of this function. We retain the following for backwards
15241525
# compatibility with pydantic users who are not using contrib.pydantic, but
15251526
# this is deprecated.
1526-
parse_obj_attr = inspect.getattr_static(hint, "parse_obj", None)
1527-
if isinstance(parse_obj_attr, classmethod) or isinstance(
1528-
parse_obj_attr, staticmethod
1529-
):
1530-
if not isinstance(value, dict):
1531-
raise TypeError(
1532-
f"Cannot convert to {hint}, value is {type(value)} not dict"
1527+
for pydantic_attr in ["model_validate", "parse_obj"]:
1528+
pydantic_method = inspect.getattr_static(hint, pydantic_attr, None)
1529+
if isinstance(pydantic_method, classmethod) or isinstance(
1530+
pydantic_method, staticmethod
1531+
):
1532+
if not isinstance(value, dict):
1533+
raise TypeError(
1534+
f"Cannot convert to {hint}, value is {type(value)} not dict"
1535+
)
1536+
warnings.warn(
1537+
"It looks like you're using pydantic. Please use temporalio.contrib.pydantic.converter.pydantic_data_converter."
15331538
)
1534-
return getattr(hint, "parse_obj")(value)
1539+
return getattr(hint, pydantic_attr)(value)
15351540

15361541
# IntEnum
15371542
if inspect.isclass(hint) and issubclass(hint, IntEnum):

0 commit comments

Comments
 (0)