Checks
Feature Request
I found mentions of a readOnly parameter on the deprecated Schema class but it was not carried over to Field. Others are using validators to enforce readonly on assignment, but it's a common enough feature that pydantic could provide it natively. I am not able to use validators to create a readonly Field because I have validators that need to be run on initialization.
Output of python -c "import pydantic.utils; print(pydantic.utils.version_info())":
pydantic version: 1.7.2
pydantic compiled: False
install path: /Users/scootna/projects/pydantic/pydantic
python version: 3.8.2 (default, Sep 24 2020, 19:37:08) [Clang 12.0.0 (clang-1200.0.32.21)]
platform: macOS-10.15.7-x86_64-i386-64bit
optional deps. installed: ['typing-extensions', 'email-validator', 'devtools']
from pydantic import BaseModel, Field
class Entry(BaseModel):
id: float = Field(allow_mutation=False)
val: float
class Config:
validate_assignment = True
r = Entry(id=1, val=100)
r.id = 2 # raise error when assigning to read_only field
...
Checks
Feature Request
I found mentions of a readOnly parameter on the deprecated Schema class but it was not carried over to Field. Others are using validators to enforce readonly on assignment, but it's a common enough feature that pydantic could provide it natively. I am not able to use validators to create a readonly Field because I have validators that need to be run on initialization.
Output of
python -c "import pydantic.utils; print(pydantic.utils.version_info())":