Skip to content

Commit 69a4504

Browse files
asiunovsvlandeg
andauthored
🐛 Fix Pydantic version check for version 2.10.x onwards (#1255)
Co-authored-by: Sofie Van Landeghem <[email protected]>
1 parent f46997e commit 69a4504

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

sqlmodel/_compat.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525

2626
# Reassign variable to make it reexported for mypy
2727
PYDANTIC_VERSION = P_VERSION
28-
IS_PYDANTIC_V2 = PYDANTIC_VERSION.startswith("2.")
28+
PYDANTIC_MINOR_VERSION = tuple(int(i) for i in P_VERSION.split(".")[:2])
29+
IS_PYDANTIC_V2 = PYDANTIC_MINOR_VERSION[0] == 2
2930

3031

3132
if TYPE_CHECKING:

sqlmodel/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656

5757
from ._compat import ( # type: ignore[attr-defined]
5858
IS_PYDANTIC_V2,
59-
PYDANTIC_VERSION,
59+
PYDANTIC_MINOR_VERSION,
6060
BaseConfig,
6161
ModelField,
6262
ModelMetaclass,
@@ -874,7 +874,7 @@ def model_dump(
874874
warnings: Union[bool, Literal["none", "warn", "error"]] = True,
875875
serialize_as_any: bool = False,
876876
) -> Dict[str, Any]:
877-
if PYDANTIC_VERSION >= "2.7.0":
877+
if PYDANTIC_MINOR_VERSION >= (2, 7):
878878
extra_kwargs: Dict[str, Any] = {
879879
"context": context,
880880
"serialize_as_any": serialize_as_any,

0 commit comments

Comments
 (0)