Skip to content

Commit a20d15b

Browse files
committed
✏️ Fix reversion in model_dump attribute handling for pydantic v2.7 .. v2.10
+ The else block added to fix linting errors (4b5ad42) for #1340 was obliterating the 'context' and 'serialize_as_any' attributes for versions >= 2.7 and < 2.11. + Fix by initializing extra_kwargs and then setting on a per-version level
1 parent 39d8c2c commit a20d15b

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

sqlmodel/main.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -863,27 +863,24 @@ def model_dump(
863863
mode: Union[Literal["json", "python"], str] = "python",
864864
include: Union[IncEx, None] = None,
865865
exclude: Union[IncEx, None] = None,
866-
context: Union[Any, None] = None,
866+
context: Union[Any, None] = None, # v2.7
867867
by_alias: Union[bool, None] = None,
868868
exclude_unset: bool = False,
869869
exclude_defaults: bool = False,
870870
exclude_none: bool = False,
871871
round_trip: bool = False,
872872
warnings: Union[bool, Literal["none", "warn", "error"]] = True,
873-
fallback: Union[Callable[[Any], Any], None] = None,
874-
serialize_as_any: bool = False,
873+
fallback: Union[Callable[[Any], Any], None] = None, # v2.11
874+
serialize_as_any: bool = False, # v2.7
875875
) -> Dict[str, Any]:
876876
if PYDANTIC_MINOR_VERSION < (2, 11):
877877
by_alias = by_alias or False
878+
extra_kwargs: Dict[str, Any] = {}
878879
if PYDANTIC_MINOR_VERSION >= (2, 7):
879-
extra_kwargs: Dict[str, Any] = {
880-
"context": context,
881-
"serialize_as_any": serialize_as_any,
882-
}
880+
extra_kwargs["context"] = context
881+
extra_kwargs["serialize_as_any"] = serialize_as_any
883882
if PYDANTIC_MINOR_VERSION >= (2, 11):
884883
extra_kwargs["fallback"] = fallback
885-
else:
886-
extra_kwargs = {}
887884
if IS_PYDANTIC_V2:
888885
return super().model_dump(
889886
mode=mode,

0 commit comments

Comments
 (0)