python
data_error
ai_generated
true
pydantic.errors.EnumError: 值不是有效的枚举成员
pydantic.errors.EnumError: value is not a valid enumeration member
ID: python/pydantic-enum-value-invalid
80%修复率
86%置信度
0证据数
2024-02-14首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 2.x | active | — | — | — |
根因分析
类型为枚举的字段接收到未在枚举中定义的值。
English
A field typed as an Enum receives a value not defined in the enumeration.
解决方案
-
95% 成功率
Use enum member: Color.RED
-
90% 成功率
Add custom validator to map strings to enum
无效尝试
常见但无效的做法:
-
80% 失败
Enum member type mismatch.
-
70% 失败
Pydantic expects the value, not name.