# pydantic.errors.PydanticUserError: `@validator` 不能应用于实例方法。请改用 `@field_validator`。

- **ID:** `python/pydantic-deprecated-validator-v1`
- **领域:** python
- **类别:** module_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

Pydantic v2 移除了 v1 的 `@validator` 装饰器；使用它（或从 `pydantic` 顶层导入）会触发用户错误。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   Replace `@validator('x')` with `@field_validator('x')` and `@classmethod`; note `values` dict becomes a second positional arg `info`.
   ```
2. **** (90% 成功率)
   ```
   Use `@model_validator(mode='after')` for cross-field validation.
   ```

## 无效尝试

- **** — Pinning to Pydantic v1 avoids the error but loses v2 performance and features. (30% 失败率)
- **** — Importing `validator` from `pydantic.deprecated` works temporarily but emits DeprecationWarning and will be removed. (50% 失败率)
