]> git.ipfire.org Git - thirdparty/fastapi/sqlmodel.git/commitdiff
🐛 Fix Pydantic version check for version 2.10.x onwards (#1255)
authorAndrey Siunov <asiunov@users.noreply.github.com>
Fri, 28 Feb 2025 14:01:13 +0000 (06:01 -0800)
committerGitHub <noreply@github.com>
Fri, 28 Feb 2025 14:01:13 +0000 (15:01 +0100)
Co-authored-by: Sofie Van Landeghem <svlandeg@users.noreply.github.com>
sqlmodel/_compat.py
sqlmodel/main.py

index 4e80cdc37418af423fe8e22a2d754c667e05e5d5..d6b98aaca7b968191417296eed430f92eccefa44 100644 (file)
@@ -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:
index 3532e81a8e5e591a528c0ff3f0b8231704ebda76..61952be2f1be29de838af0dd2d78016942426ff8 100644 (file)
@@ -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,