From 978b78a36ac1a83244eb66c968a9006103942352 Mon Sep 17 00:00:00 2001 From: Andrey Siunov Date: Mon, 23 Dec 2024 00:04:46 -0800 Subject: [PATCH] Fix context in model_dump for pydantic 2.10 --- sqlmodel/_compat.py | 3 ++- sqlmodel/main.py | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/sqlmodel/_compat.py b/sqlmodel/_compat.py index 4e80cdc374..989c09e1c7 100644 --- a/sqlmodel/_compat.py +++ b/sqlmodel/_compat.py @@ -25,7 +25,8 @@ # 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)[:2]) +IS_PYDANTIC_V2 = PYDANTIC_MINOR_VERSION[0] >= 2 if TYPE_CHECKING: diff --git a/sqlmodel/main.py b/sqlmodel/main.py index 3532e81a8e..61952be2f1 100644 --- a/sqlmodel/main.py +++ b/sqlmodel/main.py @@ -56,7 +56,7 @@ from ._compat import ( # type: ignore[attr-defined] IS_PYDANTIC_V2, - PYDANTIC_VERSION, + PYDANTIC_MINOR_VERSION, BaseConfig, ModelField, ModelMetaclass, @@ -874,7 +874,7 @@ def model_dump( 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,