diff --git a/tortoise/contrib/pydantic/utils.py b/tortoise/contrib/pydantic/utils.py index b8984b3fe..14b5819c6 100644 --- a/tortoise/contrib/pydantic/utils.py +++ b/tortoise/contrib/pydantic/utils.py @@ -1,6 +1,8 @@ import typing from typing import Any, Callable, Dict, Optional, Type +import tortoise + if typing.TYPE_CHECKING: # pragma: nocoverage from tortoise.models import Model @@ -12,4 +14,9 @@ def get_annotations(cls: "Type[Model]", method: Optional[Callable] = None) -> Di :param method: If specified, we try to get the annotations for the callable :return: The list of annotations """ - return typing.get_type_hints(method or cls) + localns = ( + tortoise.Tortoise.apps.get(cls._meta.app, None) + if cls._meta.app + else None + ) + return typing.get_type_hints(method or cls, localns=localns)