# pydantic_core._pydantic_core.ValidationError: 1 个验证错误，实例已冻结 [type=frozen_instance]

- **ID:** `python/pydantic-configerror-frozen-field-mutation`
- **领域:** python
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

BaseSettings/BaseModel 声明了 model_config = ConfigDict(frozen=True)，代码在构造之后尝试给字段赋新值。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 2.x | active | — | — |

## 解决方案

1. **** (95% 成功率)
   ```
   new_settings = settings.model_copy(update={'api_key': 'new-key'})
   ```
2. **** (90% 成功率)
   ```
   class Settings(BaseSettings):
    model_config = ConfigDict(frozen=False)
    api_key: str
   ```

## 无效尝试

- **** — Bypassing Pydantic's __setattr__ works at runtime but leaves the model's internal __pydantic_fields_set__ inconsistent and can break serialization. (55% 失败率)
- **** — frozen models also block __delattr__, raising TypeError: cannot delete field. (90% 失败率)
