Skip to content

Upgrading pydantic_core 0.42 to 2

Breaking0.42.0 → 2.50.2Breaking9Security1Platform4Deprecated7New121Changed127Fixed376Other146

Fetching 102 releases from GitHub…101 / 102
BreakingUpgrade verdict

9 breaking changes and 4 platform requirement changes and a security fix.

  • The way fields are defined when calling create_model has changed, which may require updating existing code.
  • You can no longer customize the internal schema generator because its interface may still change.
  • When you provide json_schema_extra as a dict, it is now merged with existing schema extras rather than replacing them.
  • Removes `initial_metadata` from the internal metadata construct.
Top 5 of 21 that need code or config changes

Python requirement changed in 2.47.0: >=3.7 → >=3.10.

Adds typing-extensions >=4.16.0.

Installs 1 package in all (was 0).

Breaking9
Reworks the create_model field definitions format.
create_model
Disallows customization of SchemaGenerator until its interface is more stable.
SchemaGenerator
Merges dict type json_schema_extra instead of overwriting it.
json_schema_extra
Removes initial_metadata from the internal metadata construct.
initial_metadata
Changes the metadata type hint in core schemas from Any to Dict[str, Any] | None.
metadata
Improves smart union matching logic, changing which union member matches in some cases.
smartUnion
Uses positional-only self in BaseModel constructor, so no field name can conflict with it.
BaseModel
Makes @validate_call return a function instead of a custom descriptor, fixing binding with inheritance and adding self/cls to validation errors.
@validate_call
Replaces ultra_strict with a new smart union implementation, significantly changing how unions are validated.
ultra_strict
Security1
Fixes a regular expression denial of service issue by limiting whitespaces.
Platform4
Drops support for Python 3.9 and adds support for Python 3.15.
Removes Python 3.8 support.
Adds support for Python 3.13.
Drops Python 3.7, and PyPy 3.7 and 3.8.
Deprecated7
Raises a deprecation warning when a field is annotated as final with a default value.
Deprecates accessing model_fields and model_computed_fields on instances.
model_fieldsmodel_computed_fields
Recommends against using Ellipsis (...) with Field.
FieldEllipsis
Deprecates passing a dict to the Examples class.
Examples
Deprecates the update_json_schema internal function.
update_json_schema
Marks Extra as deprecated.
Extra
Deprecates Field.include.
Field.include