Pydantic v1 to v2 migration: key renames and why deprecation warnings can mislead
Pydantic v2 rewrote its core in Rust and renamed much of its public API, so many projects encounter the same set of changes first. Common swaps include dict() becoming model_dump(), json() becoming model_dump_json(), parse_obj() becoming model_validate(), and validator becoming field_validator with mode="before" replacing pre=True. The Config class with orm_mode is replaced by model_config using ConfigDict and from_attributes. Because v2 keeps many v1 names as deprecated aliases, old code still runs and only emits PydanticDeprecatedSince20 warnings, which are easy to ignore. The article suggests turning those warnings into errors in tests and using the bump-pydantic tool, followed by a full test run since some behaviour, such as type coercion strictness, also changed.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in