Skip to content

Commit

Permalink
fix: Make get_annotations evaluate annotations in default scope (#1609)
Browse files Browse the repository at this point in the history
* fix: Make get_annotations evaluate annotations in default scope

fixes #1552

* misc: update changelog and fix lint
  • Loading branch information
WizzyGeek committed May 10, 2024
1 parent f36f8b7 commit fe11aa5
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Fixed
- Fix `DatetimeField` use '__year' report `'int' object has no attribute 'utcoffset'`. (#1575)
- Fix `bulk_update` when using custom fields. (#1564)
- Fix `optional` parameter in `pydantic_model_creator` does not work for pydantic v2. (#1551)
- Fix `get_annotations` now evaluates annotations in the default scope instead of the app namespace. (#1552)

0.20.1
------
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Contributors
* Waket Zheng ``@waketzheng``
* Yuval Ben-Arie ``@yuvalbenarie``
* Stephan Klein ``@privatwolke``
* ``@WizzyGeek``

Special Thanks
==============
Expand Down
5 changes: 1 addition & 4 deletions tortoise/contrib/pydantic/utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import typing
from typing import Any, Callable, Dict, Optional, Type

import tortoise

if typing.TYPE_CHECKING: # pragma: nocoverage
from tortoise.models import Model

Expand All @@ -14,5 +12,4 @@ 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
"""
globalns = tortoise.Tortoise.apps.get(cls._meta.app, None) if cls._meta.app else None
return typing.get_type_hints(method or cls, globalns=globalns)
return typing.get_type_hints(method or cls)

0 comments on commit fe11aa5

Please sign in to comment.