From 0402496be2c24231ae002afc58f91da4c00d1c43 Mon Sep 17 00:00:00 2001 From: Andrew Grangaard Date: Wed, 8 Oct 2025 03:33:47 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20attribute=20handling=20in?= =?UTF-8?q?=20`model=5Fdump`=20for=20compatibility=20with=20the=20latest?= =?UTF-8?q?=20Pydantic=20versions=20(#1595)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sqlmodel/main.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/sqlmodel/main.py b/sqlmodel/main.py index 38c85915..1925a48f 100644 --- a/sqlmodel/main.py +++ b/sqlmodel/main.py @@ -109,7 +109,8 @@ def __dataclass_transform__( return lambda a: a -class FieldInfo(PydanticFieldInfo): +class FieldInfo(PydanticFieldInfo): # type: ignore[misc] + # mypy - ignore that PydanticFieldInfo is @final def __init__(self, default: Any = Undefined, **kwargs: Any) -> None: primary_key = kwargs.pop("primary_key", False) nullable = kwargs.pop("nullable", Undefined) @@ -863,27 +864,27 @@ class SQLModel(BaseModel, metaclass=SQLModelMetaclass, registry=default_registry mode: Union[Literal["json", "python"], str] = "python", include: Union[IncEx, None] = None, exclude: Union[IncEx, None] = None, - context: Union[Any, None] = None, + context: Union[Any, None] = None, # v2.7 by_alias: Union[bool, None] = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, + exclude_computed_fields: bool = False, # v2.12 round_trip: bool = False, warnings: Union[bool, Literal["none", "warn", "error"]] = True, - fallback: Union[Callable[[Any], Any], None] = None, - serialize_as_any: bool = False, + fallback: Union[Callable[[Any], Any], None] = None, # v2.11 + serialize_as_any: bool = False, # v2.7 ) -> Dict[str, Any]: if PYDANTIC_MINOR_VERSION < (2, 11): by_alias = by_alias or False + extra_kwargs: Dict[str, Any] = {} if PYDANTIC_MINOR_VERSION >= (2, 7): - extra_kwargs: Dict[str, Any] = { - "context": context, - "serialize_as_any": serialize_as_any, - } + extra_kwargs["context"] = context + extra_kwargs["serialize_as_any"] = serialize_as_any if PYDANTIC_MINOR_VERSION >= (2, 11): extra_kwargs["fallback"] = fallback - else: - extra_kwargs = {} + if PYDANTIC_MINOR_VERSION >= (2, 12): + extra_kwargs["exclude_computed_fields"] = exclude_computed_fields if IS_PYDANTIC_V2: return super().model_dump( mode=mode,