Migrating to Pydantic v2.11.0a1
Version v2.11.0a1 introduces 3 breaking changes. This guide details how to update your code.
Released: 1/30/2025
⚠️ Check Your Code
If you use any of these symbols, you need to read this guide:
FieldInfoModelMetaclassTypeAdapterGenerateSchemacreate_modelcheck_pydantic_core_versionFieldInfo.default_factory_takes_validated_datapydantic.v1WithJsonSchemaCoreMetadataBreaking Changes
●Issue #1
Accessing `model_fields` or `model_computed_fields` directly on an instance of a Pydantic model is deprecated and will raise an error in the future.
✓Solution
Access `model_fields` and `model_computed_fields` on the model class instead of the instance. For example, change `instance.model_fields` to `YourModel.model_fields`.
●Issue #2
The format for defining fields when using `pydantic.create_model` has been reworked, which might break custom usage patterns.
✓Solution
Review the documentation for `create_model` in v2.11.0a1 and update how field definitions are passed, especially concerning default values or complex field configurations.
●Issue #3
Python 3.8 support has been officially removed.
✓Solution
Ensure your project is running on Python 3.9 or newer. If you require Python 3.8 compatibility, you must remain on Pydantic v2.10.x or earlier.
Migration Steps
- 1Update your Pydantic dependency to version 2.11.0a1 or later (or the final release based on this alpha).
- 2If you are using Python 3.8, upgrade your environment to Python 3.9+ before migrating, as 3.8 is no longer supported.
- 3Review any code where you access `model_fields` or `model_computed_fields` on model instances (e.g., `my_instance.model_fields`). Change these accesses to use the model class (e.g., `MyModel.model_fields`).
- 4If you extensively use `pydantic.create_model`, test your model creation logic thoroughly, as the field definition format has been reworked.
- 5If you encounter any unexpected behavior related to generics (especially PEP 695 syntax or type variables with defaults/bounds), ensure your type hints are correctly structured according to the new support.
Release Summary
Pydantic v2.11.0a1 is an alpha release focused on improving build-time performance for core schema generation and Pydantic models. It introduces support for PEP 695 syntax and removes support for Python 3.8.
Need More Details?
View the full release notes and all changes for Pydantic v2.11.0a1.
View Full Changelog