Upgrade to Pydantic 2.11
Recipe ID
org.openrewrite.python.migrate.pydantic.UpgradeToPydantic211Artifactopenrewrite-migrate-pythonMigrate code affected by deprecations introduced in Pydantic 2.11 (and 2.10). Rewrites instance access of model_fields / model_computed_fields to class access, rewrites Final model fields with default values to ClassVar, and renames populate_by_name to validate_by_name.
Composite recipepythonpydanticmigration2.11Proprietary
Usage
This recipe has no required configuration options. You’ll need the Moderne CLI configured before running the command below.
mod run . --recipe org.openrewrite.python.migrate.pydantic.UpgradeToPydantic211If the recipe isn’t available locally, install it with:
mod config recipes pip install openrewrite-migrate-pythonDefinition
This recipe runs the following recipes in order.
- Upgrade to Pydantic 2.10
org.openrewrite.python.migrate.pydantic.UpgradeToPydantic210 - Replace instance access of
model_fields/model_computed_fieldsorg.openrewrite.python.migrate.pydantic.ReplaceModelFieldsInstanceAccess - Replace
Finalmodel fields with a default withClassVarorg.openrewrite.python.migrate.pydantic.ReplaceFinalFieldWithClassVar - Replace
populate_by_namewithvalidate_by_nameorg.openrewrite.python.migrate.pydantic.ReplacePopulateByNameWithValidateByName