python
data_error
ai_generated
true
pydantic.error_wrappers.ValidationError:User 有 1 个验证错误
pydantic.error_wrappers.ValidationError: 1 validation error for User
ID: python/fastapi-pydantic-validationerror
80%修复率
87%置信度
0证据数
2025-09-15首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 2.x | active | — | — | — |
| 2.5.x | active | — | — | — |
根因分析
传递给 Pydantic 模型的数据与其模式不匹配。
English
Data passed to a Pydantic model doesn't match its schema.
解决方案
-
95% 成功率
User(name='John', age=30) # age must be int
-
90% 成功率
@field_validator('age') def parse_age(cls, v): return int(v)
无效尝试
常见但无效的做法:
-
70% 失败
Only ignores extra fields, not type errors.
-
90% 失败
Same validation applies.