Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/cloudflare/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,8 @@ def model_dump(
raise ValueError("fallback is only supported in Pydantic v2")
if exclude_computed_fields != False:
raise ValueError("exclude_computed_fields is only supported in Pydantic v2")
if polymorphic_serialization is not None:
raise ValueError("polymorphic_serialization is only supported in Pydantic v2")
dumped = super().dict( # pyright: ignore[reportDeprecated]
include=include,
exclude=exclude,
Expand Down Expand Up @@ -398,6 +400,8 @@ def model_dump_json(
raise ValueError("ensure_ascii is only supported in Pydantic v2")
if exclude_computed_fields != False:
raise ValueError("exclude_computed_fields is only supported in Pydantic v2")
if polymorphic_serialization is not None:
raise ValueError("polymorphic_serialization is only supported in Pydantic v2")
return super().json( # type: ignore[reportDeprecated]
indent=indent,
include=include,
Expand Down
15 changes: 15 additions & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,21 @@ class Model2(BaseModel):
m.to_dict(warnings=False)


def test_polymorphic_serialization_is_rejected_on_pydantic_v1() -> None:
class Model(BaseModel):
foo: int = 1

m = Model()
if PYDANTIC_V1:
with pytest.raises(ValueError, match="polymorphic_serialization is only supported in Pydantic v2"):
m.model_dump(polymorphic_serialization=True)
with pytest.raises(ValueError, match="polymorphic_serialization is only supported in Pydantic v2"):
m.model_dump_json(polymorphic_serialization=True)

# the default must keep working on both major versions
assert m.model_dump() == {"foo": 1}


def test_forwards_compat_model_dump_method() -> None:
class Model(BaseModel):
foo: Optional[str] = Field(alias="FOO", default=None)
Expand Down