python
config_error
ai_generated
true
pydantic.errors.ConfigError: 无效的验证器签名
pydantic.errors.ConfigError: Invalid validator signature
ID: python/pydantic-validator-wrong-signature
80%修复率
88%置信度
0证据数
2024-02-05首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 2.x | active | — | — | — |
根因分析
@field_validator 或 @model_validator 函数的参数数量或名称不正确(例如缺少 cls 或 value)。
English
A @field_validator or @model_validator function has an incorrect number or names of arguments (e.g., missing cls or value).
解决方案
-
95% 成功率
Define correctly: @field_validator('field') def validate(cls, v): return v -
90% 成功率
For model validator: @model_validator(mode='after') def validate(self): return self
无效尝试
常见但无效的做法:
-
90% 失败
Pydantic expects at least two arguments: cls and value.
-
80% 失败
Validators are class methods, not instance methods.