Migrating to Pydantic v2.11.0b1
Version v2.11.0b1 introduces 5 breaking changes. This guide details how to update your code.
Released: 3/6/2025
⚠️ Check Your Code
If you use any of these symbols, you need to read this guide:
GenerateSchemaFieldInfoTypeAdapterModelMetaclassClickHouseDsncheck_pydantic_core_versionBaseModel.model_fieldsBaseModel.model_computed_fieldsGenerateJsonSchema.literal_schemaBreaking Changes
●Issue #1
Fields annotated with `typing.Final` that also have a default value are now treated as private model attributes instead of class variables.
✓Solution
If you intend for the attribute to remain a class variable (not part of the model's data/schema), use `typing.ClassVar` instead of `typing.Final` for the annotation.
●Issue #2
Accessing `model_fields` or `model_computed_fields` directly on an instance of a Pydantic model is deprecated.
✓Solution
Access these attributes on the model class itself (e.g., `MyModel.model_fields`) instead of the instance (e.g., `instance.model_fields`).
●Issue #3
Core schema generation logic for path types has been moved inside the `GenerateSchema` class.
✓Solution
This is an internal change. If you were relying on internal Pydantic schema generation APIs related to path types, you will need to update your usage to reflect the new location within `GenerateSchema`.
●Issue #4
Support for Python 3.8 has been removed.
✓Solution
Ensure your project targets Python 3.9 or newer.
●Issue #5
The format for defining fields when using `create_model` has been reworked.
✓Solution
Review your usage of `pydantic.create_model` and update how field definitions (especially those involving defaults or metadata) are passed.
Migration Steps
- 1Review all model fields annotated with `typing.Final` that possess a default value. If these should remain class variables, change the annotation from `Final[T] = value` to `ClassVar[T] = value`.
- 2Update any code that accesses `model_fields` or `model_computed_fields` on model instances to access these attributes on the model class instead (e.g., change `instance.model_fields` to `ModelName.model_fields`).
- 3If your project relies on Python 3.8, upgrade your environment to Python 3.9 or later, as 3.8 support has been dropped.
- 4If you use `pydantic.create_model`, check the documentation for v2.11.0b1 regarding the reworked field definition format and adjust your calls accordingly.
- 5If you encounter issues related to schema generation for path types, consult the Pydantic source or documentation regarding the internal `GenerateSchema` class.
Release Summary
Pydantic v2.11.0b1 drops Python 3.8 support, introduces full PEP 695 support, and optimizes performance through improved caching and schema building. It also refactors internal schema generation and updates the behavior of Final attributes.
Need More Details?
View the full release notes and all changes for Pydantic v2.11.0b1.
View Full Changelog