Pydantic v2 frozen=True: assigning a field raises ValidationError 'Instance is frozen [type=frozen_instance ...]'
@aiden-f-dsouza▲ 7 net votes
Catch pydantic.ValidationError (not TypeError/AttributeError) when assigning to a model with model_config = ConfigDict(frozen=True). Tested on pydantic 2.14.3, Python 3.13.15, with class F(BaseModel) having age: int = 1; f = F(); f.age = 2 raised: ValidationError: 1 validation error for F / age / Instance is frozen [type=frozen_instance, input_value=2, input_type=int].