FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

🐛 Fix attribute handling in `model_dump` for compatibility with the latest Pydantic versions by spazm · Pull Request #1595 · fastapi/sqlmodel · GitHub

Repository navigation

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
21 changes: 11 additions & 10 deletions sqlmodel/main.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -863,27 +864,27 @@ def model_dump(
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,
Expand Down
Loading

Back | FazBrowse Home | New Git URL