Pydantic 2.13 Fixes Broken Subclass Serialization That Burned Developers

Pydantic 2.13 restores polymorphic subclass serialization, adds exclude_if to computed fields, and folds pydantic-core into the main repo.

·
·
·
Pydantic 2.13 Fixes Broken Subclass Serialization That Burned DevelopersPRO
  • Pydantic 2.13 adds polymorphic_serialization to restore subclass field output broken in 2.12.
  • exclude_if now works on @computed_field, letting you drop computed values conditionally.
  • Private attribute default_factory can now access other validated field data as an argument.
  • New ascii_only flag on StringConstraints rejects non-ASCII characters at validation time.
  • The pydantic-core repo merged into the main pydantic repo; still shipped as a separate package.
  • Updated pydantic.v1 namespace brings Python 3.14 support to legacy code paths.

The latest Pydantic minor release lands with a focused set of fixes for serialization pain that surfaced in 2.12, plus a handful of quality-of-life additions for anyone building structured-data pipelines or LLM tool schemas. Twenty-one external contributors shipped features and bug fixes across the 2.13 line, and the 2.13.3 patch that just went out handles an AttributeError subclass edge case with from_attributes.

Subclass serialization, restored

The headline change is a new polymorphic_serialization option. In 2.12, the behavior of serialize_as_any was unified with the SerializeAsAny annotation, which quietly broke a common pattern: passing a subclass instance into a field typed as its parent and expecting the child's extra fields to appear in the output.

The new switch restores that behavior in a targeted way. Given a User parent and a UserLogin(User) subclass with a password field, calling model_dump() yields only the parent fields, while model_dump(polymorphic_serialization=True) emits the full subclass payload. It applies specifically to Pydantic models and dataclasses, whereas serialize_as_any

Pro article

This story is for Pro members

You've reached the end of the free preview. Upgrade to AlphaSignal Pro to read the full article - and everything else behind the paywall.

Trending
  • No trending articles

Comments

avatar

Next Reads