|
10 | 10 | import sys |
11 | 11 | import traceback |
12 | 12 | import uuid |
| 13 | +import warnings |
13 | 14 | from abc import ABC, abstractmethod |
14 | 15 | from dataclasses import dataclass |
15 | 16 | from datetime import datetime |
@@ -1523,15 +1524,19 @@ def value_to_type( |
1523 | 1524 | # the start of this function. We retain the following for backwards |
1524 | 1525 | # compatibility with pydantic users who are not using contrib.pydantic, but |
1525 | 1526 | # 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." |
1533 | 1538 | ) |
1534 | | - return getattr(hint, "parse_obj")(value) |
| 1539 | + return getattr(hint, pydantic_attr)(value) |
1535 | 1540 |
|
1536 | 1541 | # IntEnum |
1537 | 1542 | if inspect.isclass(hint) and issubclass(hint, IntEnum): |
|
0 commit comments