From d9be22044d251c047b6306e767b2537c0ee12709 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Thu, 27 Apr 2023 23:00:18 -0400 Subject: [PATCH] adjust fwd_ref logic Fixed issue where ORM Annotated Declarative would not resolve forward references correctly in all cases; in particular, when using ``from __future__ import annotations`` in combination with Pydantic dataclasses. Change-Id: If643c9a4ac7e217d4cb3a7d09b96cfd49432c44e References: #9717 --- doc/build/changelog/unreleased_20/9717.rst | 8 ++++++++ lib/sqlalchemy/util/typing.py | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 doc/build/changelog/unreleased_20/9717.rst diff --git a/doc/build/changelog/unreleased_20/9717.rst b/doc/build/changelog/unreleased_20/9717.rst new file mode 100644 index 0000000000..d70ffe17a8 --- /dev/null +++ b/doc/build/changelog/unreleased_20/9717.rst @@ -0,0 +1,8 @@ +.. change:: + :tags: bug, orm + :tickets: 9717 + + Fixed issue where ORM Annotated Declarative would not resolve forward + references correctly in all cases; in particular, when using + ``from __future__ import annotations`` in combination with Pydantic + dataclasses. diff --git a/lib/sqlalchemy/util/typing.py b/lib/sqlalchemy/util/typing.py index 9c38ae3443..3ac67aad9a 100644 --- a/lib/sqlalchemy/util/typing.py +++ b/lib/sqlalchemy/util/typing.py @@ -146,7 +146,7 @@ def de_stringify_annotation( original_annotation = annotation - if is_fwd_ref(annotation) and not annotation.__forward_evaluated__: + if is_fwd_ref(annotation): annotation = annotation.__forward_arg__ if isinstance(annotation, str): -- 2.39.5