python config_error ai_generated true

PydanticUserError: `orm_mode` is removed. Use `from_attributes=True` instead.

ID: python/fastapi-pydantic-config-orm-mode

Also available as: JSON · Markdown · 中文
80%Fix Rate
89%Confidence
0Evidence
2024-05-09First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.x active — — —

Root Cause

A Pydantic model still uses v1's `orm_mode = True` Config under v2.

generic

中文

Pydantic 模型在 v2 下仍使用 v1 的 `orm_mode = True` 配置。

Workarounds

  1. 93% success
    Use v2 config:
    class UserOut(BaseModel):
        model_config = ConfigDict(from_attributes=True)
  2. 85% success
    Validate manually with model_validate(obj, from_attributes=True).

Dead Ends

Common approaches that don't work:

  1. 90% fail

    orm_mode is rejected outright, so the model fails to import.

  2. 70% fail

    Then ORM objects can't be validated from attributes, breaking response_model.