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.
In plain terms
- 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.
Must act 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).
What you must change
Breaking9
Reworks the
create_model field definitions format.create_modelDisallows customization of
SchemaGenerator until its interface is more stable.SchemaGeneratorMerges dict type json_schema_extra instead of overwriting it.
json_schema_extraRemoves
initial_metadata from the internal metadata construct.initial_metadataChanges the
metadata type hint in core schemas from Any to Dict[str, Any] | None.metadataImproves smart union matching logic, changing which union member matches in some cases.
smartUnionUses positional-only self in BaseModel constructor, so no field name can conflict with it.
BaseModelMakes @validate_call return a function instead of a custom descriptor, fixing binding with inheritance and adding self/cls to validation errors.
@validate_callReplaces ultra_strict with a new smart union implementation, significantly changing how unions are validated.
ultra_strictSecurity1
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.
Deprecations to plan for
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_fieldsRecommends against using
Ellipsis (...) with Field.FieldEllipsisDeprecates passing a dict to the
Examples class.ExamplesDeprecates the
update_json_schema internal function.update_json_schemaMarks Extra as deprecated.
ExtraDeprecates
Field.include.Field.include