Expose fallback parameter in serialization methods by Viicos · Pull Request #11398 · pydantic/pydantic (original) (raw)

jdeschamps added a commit to CAREamics/careamics that referenced this pull request

May 5, 2025

@melisande-c @jdeschamps

…#465)

Description

[!NOTE]
tldr: Pydantic BaseModel.model_dump function signature in 2.11 is not back compatible with 2.10. This PR sets the Pydantic lower bound version to 2.11 and bumps the upper bound to 2.12.

Background - why do we need this PR?

The reason we need this PR is because we override the model_dump method in the Configuration class. Pydantic 2.11 introduces a new fallback argument and also changes the type of by_alias to bool | None from bool. These were introduced in the PRs pydantic/pydantic#11398 and pydantic/pydantic#11468 respectively.

If we do not update the function signature mypy tells us that we have overridden the function in a way that is incompatible with the base class, if we do update the signature it is no longer compatible with Pydantic 2.10. I have updated the signature so we can continue to use newer versions of Pydantic.

Overview - what changed?

Updated pyproject.toml and Configuration.model_dump.

Breaking changes

This will cause the same backwards compatibility issue in CAREamics as Pydantic, but it should not break existing code.


Please ensure your PR meets the following requirements:

Co-authored-by: Joran Deschamps 6367888+jdeschamps@users.noreply.github.com