]> git.ipfire.org Git - thirdparty/fastapi/sqlmodel.git/commitdiff
🐛 Fix attribute handling in `model_dump` for compatibility with the latest Pydantic...
authorAndrew Grangaard <andrew.grangaard@gmail.com>
Wed, 8 Oct 2025 10:33:47 +0000 (03:33 -0700)
committerGitHub <noreply@github.com>
Wed, 8 Oct 2025 10:33:47 +0000 (12:33 +0200)
sqlmodel/main.py

index 38c85915aa352e62eda8494aa5f2d5775f74dd1a..1925a48f04174fabd6e7d055be437ec957dd455f 100644 (file)
@@ -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,