🐛 Fix Pydantic version check for version 2.10.x onwards (#1255)

Co-authored-by: Sofie Van Landeghem <svlandeg@users.noreply.github.com>
This commit is contained in:
Andrey Siunov
2025-02-28 06:01:13 -08:00
committed by GitHub
parent f46997ec6d
commit 69a4504a33
2 changed files with 4 additions and 3 deletions

View 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:

View 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,