F40 Change Proposal: Update to Pydantic Version 2 (Self-Contained)

Update To Pydantic Version 2

This is a proposed Change for Fedora Linux.
This document represents a proposed Change. As part of the Changes process, proposals are publicly announced in order to receive community feedback. This proposal will only be implemented if approved by the Fedora Engineering Steering Committee.

:link: Summary

python-pydantic, a Python data validation library, will be updated from 1.10.z to 2.y.z. The Change owners will perform a test rebuild and work with package maintainers and upstreams to port code.

:link: Owner[edit]

:link: Detailed Description

Pydantic is a Python data validation library. Recently, upstream released major version 2 with many fixes and performance improvements but also multiple breaking API changes. The new release relies on python-pydantic-core, which provides the core validation and serialization functionality used by pydantic v2. pydantic-core is a Rust PyO3 Python extension module.

We will update pydantic to version 2 after making sure dependent packages are accounted for.

:link: Porting strategies

Pydantic v2 contains some breaking API changes that may require porting if packages depend on old functionality. Upstream provides a detailed Migration Guide that describes the breaking API changes.

Projects that are not ready to port to pydantic v2 may use the pydantic.v1 compatibility module which contains a full copy of the old pydantic v1 code. https://github.com/matrix-org/synapse/pull/16332 exemplifies this approach. As shown in the above PR, projects can use conditional imports to import pydantic.v1 if pydantic v2 is in use and otherwise fall back to importing pydantic if pydantic v1 is in use.

Maintaining compatibility for both pydantic v1 and v2 in the same codebase without the compatibility module is possible but may not be practical for larger, more complex usecases. fedrq uses this approach and silences pydantic.PydanticDeprecatedSince20 warnings. Many of these deprecation warnings cannot be resolved without dropping support for pydantic v1.

:link: Feedback

I did not receive much feedback as of yet, but I expect this change to be uncontroversial.

:link: Benefit to Fedora

Fedora will have the latest version of pydantic in its repositories. The new version touts a significant performance boost, amongst other improvements.

:link: Scope

  • Proposal owners:

    • Preform an impact check
    • Make an inventory of failures or packages that have a hard dependency on pydantic v1.
    • Submit distgit PRs and/or file upstream issues to fix incompatibilities in dependent packages
    • Submit new python-pydantic-settings and python-pydantic-extra-types packages for review
    • Wait two weeks for packagers to review PRs. Those that remain compatible with pydantic v1 can be merged immediately.
    • Build pydantic v2 package and any outstanding PRs in a side tag.
  • Other developers:

    • Test your package to ensure it still builds and functions with pydantic v2
    • Help with package reviews
    • Review distgit PRs to fix incompatibilities

:link: Upgrade/compatibility impact

Pydantic version 2 has some breaking API changes. See upstream’s Migration Guide.

:link: How To Test

You can perform test builds like this:

$ copr mock-config gotmax23/pydanticv2-testing fedora-rawhide-x86_64 > ~/.config/pydanticv2.cfg $ fedpkg --release=rawhide mockbuild --root pydanticv2

:link: User Experience

This isn’t a particularly user visible change. Users of Python applications that utilize Pydantic should notice a performance improvement.

:link: Dependencies

See Pydantic v2 update - Maxwell G (@gotmax23) for a list of dependent packages. The Change owners will work with these packages’ maintainers to ensure the packages remain functional with the new pydantic version.

:link: Contingency Plan

  • Contingency mechanism: N/A (not a System Wide Change)
  • Contingency deadline: N/A (not a System Wide Change)
  • Blocks release? N/A (not a System Wide Change)

:link: Documentation

See Pydantic v2 update - Maxwell G (@gotmax23) for the current status and notes.

:link: Release Notes

python3-pydantic was updated from 1.10.z to 2.y.z. Pydantic v2 brings performance improvements and an API refactoring, amongst other changes. See upstream’s Migration Guide for a full inventory of breaking changes.

1 Like

How many dependencies does python-pydantic have? Should this be categorized as a system-wide change if there are going to be dependent packages that need to change?

From Pydantic v2 update - Maxwell G (@gotmax23), there are 14 source packages that require Pydantic. Two of them (matrix-synapse and python-rstcheck-core) will require patches or updates, the details of which are already known and tested in COPR. The remaining packages are already compatible in Rawhide. I think that seems like a narrow enough impact to be considered self-contained.

1 Like