python
config_error
ai_generated
true
pydantic.errors.ConfigError: model is immutable
ID: python/pydantic-model-config-immutable
80%Fix Rate
86%Confidence
0Evidence
2024-02-18First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 2.x | active | — | — | — |
Root Cause
Attempting to modify a field of a model that has frozen=True in config, raising ConfigError.
generic中文
尝试修改配置了 frozen=True 的模型的字段,引发 ConfigError。
Workarounds
-
95% success
Remove frozen=True from model config
-
90% success
Use model_copy(update={'field': new_value}) to create a new instance
Dead Ends
Common approaches that don't work:
-
90% fail
Frozen models disallow attribute setting.
-
40% fail
This works but doesn't modify original; may be acceptable.