python
config_error
ai_generated
true
pydantic.errors.ConfigError: 模型不可变
pydantic.errors.ConfigError: model is immutable
ID: python/pydantic-model-config-immutable
80%修复率
86%置信度
0证据数
2024-02-18首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 2.x | active | — | — | — |
根因分析
尝试修改配置了 frozen=True 的模型的字段,引发 ConfigError。
English
Attempting to modify a field of a model that has frozen=True in config, raising ConfigError.
解决方案
-
95% 成功率
Remove frozen=True from model config
-
90% 成功率
Use model_copy(update={'field': new_value}) to create a new instance
无效尝试
常见但无效的做法:
-
90% 失败
Frozen models disallow attribute setting.
-
40% 失败
This works but doesn't modify original; may be acceptable.