# PydanticDeprecatedSince20: `__fields__` 已弃用，请改用 `model_fields`

- **ID:** `python/pydantic-v2-model-fields-deprecated`
- **领域:** python
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

为 Pydantic v1 编写的代码访问 model.__fields__ 或 .dict()/.json()，这些在 v2 中已弃用，应改用 model_fields、model_dump()、model_dump_json()。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 2.x | active | — | — |

## 解决方案

1. **** (95% 成功率)
   ```
   Replace attribute access:

# v1
for name, field in User.__fields__.items(): ...
# v2
for name, field in User.model_fields.items(): ...
   ```
2. **** (95% 成功率)
   ```
   Replace serialization methods:

obj.dict()      -> obj.model_dump()
obj.json()      -> obj.model_dump_json()
obj.parse_obj(d) -> obj.model_validate(d)
   ```

## 无效尝试

- **** — Hides the deprecation but the code still breaks when upgrading to v3 or when stderr is treated as failure in CI. (65% 失败率)
- **** — Conflicts with libraries (FastAPI 0.100+, LangChain) that require v2, causing install errors. (75% 失败率)
