From ec16e64484628fdc5c6790179b8c0684ea09e76a Mon Sep 17 00:00:00 2001 From: eyllanesc-JE Date: Mon, 6 Jan 2025 01:21:47 -0500 Subject: [PATCH 1/2] Add localns to get_annotations --- tortoise/contrib/pydantic/utils.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tortoise/contrib/pydantic/utils.py b/tortoise/contrib/pydantic/utils.py index b8984b3fe..3ee1d55a0 100644 --- a/tortoise/contrib/pydantic/utils.py +++ b/tortoise/contrib/pydantic/utils.py @@ -12,4 +12,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) From 06c10a32bce785abf76631990420a7dd27b41b3d Mon Sep 17 00:00:00 2001 From: eyllanesc-JE Date: Mon, 6 Jan 2025 01:29:21 -0500 Subject: [PATCH 2/2] Update utils.py --- tortoise/contrib/pydantic/utils.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tortoise/contrib/pydantic/utils.py b/tortoise/contrib/pydantic/utils.py index 3ee1d55a0..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