Skip to content

Commit 881a452

Browse files
committed
fetch raw_annotations as in Pydantic PR 11991
1 parent 778f887 commit 881a452

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

sqlmodel/_compat.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import sys
12
import types
23
from contextlib import contextmanager
34
from contextvars import ContextVar
@@ -123,7 +124,14 @@ def init_pydantic_private_attrs(new_object: InstanceOrType["SQLModel"]) -> None:
123124
object.__setattr__(new_object, "__pydantic_private__", None)
124125

125126
def get_annotations(class_dict: Dict[str, Any]) -> Dict[str, Any]:
126-
return class_dict.get("__annotations__", {}) # type: ignore[no-any-return]
127+
raw_annotations: dict[str, Any] = class_dict.get("__annotations__", {})
128+
if sys.version_info >= (3, 14) and "__annotations__" not in class_dict:
129+
# See https://github.com/pydantic/pydantic/pull/11991
130+
from annotationlib import Format, call_annotate_function, get_annotate_from_class_namespace
131+
132+
if annotate := get_annotate_from_class_namespace(class_dict):
133+
raw_annotations = call_annotate_function(annotate, format=Format.FORWARDREF)
134+
return raw_annotations
127135

128136
def is_table_model_class(cls: Type[Any]) -> bool:
129137
config = getattr(cls, "model_config", {})

0 commit comments

Comments
 (0)