First Check
Commit to Help
Example Code
import pytest
import sqlmodel
import pydantic
class MyPydanticModel(pydantic.BaseModel):
id: str
data: str = pydantic.Field(allow_mutation=False)
class Config:
validate_assignment = True
class MySqlmodelModel(sqlmodel.SQLModel):
id: str
data: str = sqlmodel.Field(allow_mutation=False)
class Config:
validate_assignment = True
class TestSuite:
def test_pydantic_can_create(self):
MyPydanticModel(id='abc', data="foo")
def test_pydantic_raises_on_update(self):
my_pyd_mdl = MyPydanticModel(id='abc', data="foo")
with pytest.raises(TypeError):
my_pyd_mdl.data = "bar"
def test_sqlmodel_can_create(self):
MySqlmodelModel(id='abc', data="foo")
def test_sqlmodel_raises_on_update(self):
my_sqlmdl_mdl = MySqlmodelModel(id='abc', data="foo")
with pytest.raises(TypeError):
my_sqlmdl_mdl.data = "bar"
Description
When setting a Field(allow_mutation=False) in combination with the required validate_assignment = True configuration on a SQLModel, the framework doesn't even allow the field to be set in the initial construction of the model. This is allowed in pydantic. I've attached a test suite that we should expect to pass, but it fails both the SQLModel specific tests.
Operating System
macOS
Operating System Details
Big Sur 11.3.1
SQLModel Version
0.0.6
Python Version
3.9.9
Additional Context
No response
First Check
Commit to Help
Example Code
Description
When setting a
Field(allow_mutation=False)in combination with the requiredvalidate_assignment = Trueconfiguration on aSQLModel, the framework doesn't even allow the field to be set in the initial construction of the model. This is allowed inpydantic. I've attached a test suite that we should expect to pass, but it fails both theSQLModelspecific tests.Operating System
macOS
Operating System Details
Big Sur 11.3.1
SQLModel Version
0.0.6
Python Version
3.9.9
Additional Context
No response