← All recipes
Moderne licensed

Replace instance access of model_fields / model_computed_fields

Recipe IDorg.openrewrite.python.migrate.pydantic.ReplaceModelFieldsInstanceAccessArtifactopenrewrite-migrate-python

Pydantic 2.11 deprecated accessing model_fields and model_computed_fields on a model instance; these are removed in Pydantic 3.0. Replace <instance>.model_fields with type(<instance>).model_fields (and likewise for model_computed_fields) when the receiver resolves to a Pydantic model, so the attribute is accessed on the class. Class access and cls access are left untouched.

Single 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.ReplaceModelFieldsInstanceAccess

If the recipe isn’t available locally, install it with:

mod config recipes pip install openrewrite-migrate-python