Skip to content

Commit 2c311df

Browse files
committed
Retain hack for backwards compatiblity
1 parent 3500b0c commit 2c311df

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

temporalio/converter.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,6 +1516,23 @@ def value_to_type(
15161516
# TODO(cretz): Want way to convert snake case to camel case?
15171517
return hint(**field_values)
15181518

1519+
# Pydantic model instance
1520+
# Pydantic users should use
1521+
# temporalio.contrib.pydantic.pydantic_data_converter, in which case a
1522+
# pydantic model instance will have been handled by the custom_converters at
1523+
# the start of this function. We retain the following for backwards
1524+
# compatibility with pydantic users who are not using contrib.pydantic, but
1525+
# 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"
1533+
)
1534+
return getattr(hint, "parse_obj")(value)
1535+
15191536
# IntEnum
15201537
if inspect.isclass(hint) and issubclass(hint, IntEnum):
15211538
if not isinstance(value, int):

0 commit comments

Comments
 (0)