Skip to content

Commit fd08465

Browse files
committed
🔄 Merge branch 'main' into pdm
2 parents 789736b + f67867f commit fd08465

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

docs/release-notes.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Latest Changes
44

5+
### Refactors
6+
7+
* ♻️ Refactor types to properly support Pydantic 2.7. PR [#913](https://github.com/tiangolo/sqlmodel/pull/913) by [@tiangolo](https://github.com/tiangolo).
8+
59
### Docs
610

711
* 📝 Update ModelRead to ModelPublic documentation and examples. PR [#885](https://github.com/tiangolo/sqlmodel/pull/885) by [@estebanx64](https://github.com/estebanx64).

sqlmodel/_compat.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@
1818
Union,
1919
)
2020

21-
from pydantic import VERSION as PYDANTIC_VERSION
21+
from pydantic import VERSION as P_VERSION
2222
from pydantic import BaseModel
2323
from pydantic.fields import FieldInfo
2424
from typing_extensions import get_args, get_origin
2525

26+
# Reassign variable to make it reexported for mypy
27+
PYDANTIC_VERSION = P_VERSION
2628
IS_PYDANTIC_V2 = PYDANTIC_VERSION.startswith("2.")
2729

2830

sqlmodel/main.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from enum import Enum
77
from pathlib import Path
88
from typing import (
9+
TYPE_CHECKING,
910
AbstractSet,
1011
Any,
1112
Callable,
@@ -55,6 +56,7 @@
5556

5657
from ._compat import ( # type: ignore[attr-defined]
5758
IS_PYDANTIC_V2,
59+
PYDANTIC_VERSION,
5860
BaseConfig,
5961
ModelField,
6062
ModelMetaclass,
@@ -80,6 +82,12 @@
8082
)
8183
from .sql.sqltypes import GUID, AutoString
8284

85+
if TYPE_CHECKING:
86+
from pydantic._internal._model_construction import ModelMetaclass as ModelMetaclass
87+
from pydantic._internal._repr import Representation as Representation
88+
from pydantic_core import PydanticUndefined as Undefined
89+
from pydantic_core import PydanticUndefinedType as UndefinedType
90+
8391
_T = TypeVar("_T")
8492
NoArgAnyCallable = Callable[[], Any]
8593
IncEx = Union[Set[int], Set[str], Dict[int, Any], Dict[str, Any], None]
@@ -764,13 +772,22 @@ def model_dump(
764772
mode: Union[Literal["json", "python"], str] = "python",
765773
include: IncEx = None,
766774
exclude: IncEx = None,
775+
context: Union[Dict[str, Any], None] = None,
767776
by_alias: bool = False,
768777
exclude_unset: bool = False,
769778
exclude_defaults: bool = False,
770779
exclude_none: bool = False,
771780
round_trip: bool = False,
772-
warnings: bool = True,
781+
warnings: Union[bool, Literal["none", "warn", "error"]] = True,
782+
serialize_as_any: bool = False,
773783
) -> Dict[str, Any]:
784+
if PYDANTIC_VERSION >= "2.7.0":
785+
extra_kwargs: Dict[str, Any] = {
786+
"context": context,
787+
"serialize_as_any": serialize_as_any,
788+
}
789+
else:
790+
extra_kwargs = {}
774791
if IS_PYDANTIC_V2:
775792
return super().model_dump(
776793
mode=mode,
@@ -782,6 +799,7 @@ def model_dump(
782799
exclude_none=exclude_none,
783800
round_trip=round_trip,
784801
warnings=warnings,
802+
**extra_kwargs,
785803
)
786804
else:
787805
return super().dict(

0 commit comments

Comments
 (0)