From: Andrey Siunov Date: Fri, 28 Feb 2025 14:01:13 +0000 (-0800) Subject: 🐛 Fix Pydantic version check for version 2.10.x onwards (#1255) X-Git-Tag: 0.0.23~6 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=69a4504a3302b0afe7b716fa7a9349829d5fc930;p=thirdparty%2Ffastapi%2Fsqlmodel.git 🐛 Fix Pydantic version check for version 2.10.x onwards (#1255) Co-authored-by: Sofie Van Landeghem --- diff --git a/sqlmodel/_compat.py b/sqlmodel/_compat.py index 4e80cdc3..d6b98aac 100644 --- a/sqlmodel/_compat.py +++ b/sqlmodel/_compat.py @@ -25,7 +25,8 @@ from typing_extensions import Annotated, get_args, get_origin # Reassign variable to make it reexported for mypy PYDANTIC_VERSION = P_VERSION -IS_PYDANTIC_V2 = PYDANTIC_VERSION.startswith("2.") +PYDANTIC_MINOR_VERSION = tuple(int(i) for i in P_VERSION.split(".")[:2]) +IS_PYDANTIC_V2 = PYDANTIC_MINOR_VERSION[0] == 2 if TYPE_CHECKING: diff --git a/sqlmodel/main.py b/sqlmodel/main.py index 3532e81a..61952be2 100644 --- a/sqlmodel/main.py +++ b/sqlmodel/main.py @@ -56,7 +56,7 @@ from typing_extensions import Literal, TypeAlias, deprecated, get_origin from ._compat import ( # type: ignore[attr-defined] IS_PYDANTIC_V2, - PYDANTIC_VERSION, + PYDANTIC_MINOR_VERSION, BaseConfig, ModelField, ModelMetaclass, @@ -874,7 +874,7 @@ class SQLModel(BaseModel, metaclass=SQLModelMetaclass, registry=default_registry warnings: Union[bool, Literal["none", "warn", "error"]] = True, serialize_as_any: bool = False, ) -> Dict[str, Any]: - if PYDANTIC_VERSION >= "2.7.0": + if PYDANTIC_MINOR_VERSION >= (2, 7): extra_kwargs: Dict[str, Any] = { "context": context, "serialize_as_any": serialize_as_any,