First Check
EDIT: See #406 (comment)
Commit to Help
Example Code
import enum
from pydantic import BaseModel, ValidationError
from sqlmodel import Field, SQLModel
class EnumValues(str, enum.Enum):
FOO = "foo"
BAR = "bar"
class TableModel(BaseModel):
value: EnumValues
print(TableModel(value="bar")) # value=<EnumValues.BAR: 'bar'>
try:
print(TableModel(value="baz"))
except ValidationError as e:
print(e)
# 1 validation error for TableModel
# value
# value is not a valid enumeration member; permitted: 'foo', 'bar' (type=type_error.enum; enum_values=[<EnumValues.FOO: 'foo'>, <EnumValues.BAR: 'bar'>])
class TableBase(SQLModel):
value: EnumValues
print(TableBase(value="bar")) # value=<EnumValues.BAR: 'bar'>
try:
print(TableBase(value="baz"))
except ValidationError as e:
print(e)
# 1 validation error for TableBase
# value
# value is not a valid enumeration member; permitted: 'foo', 'bar' (type=type_error.enum; enum_values=[<EnumValues.FOO: 'foo'>, <EnumValues.BAR: 'bar'>])
class Table(TableBase, table=True):
id: int | None = Field(default=None, nullable=False, primary_key=True) # noqa: VNE003
print(Table(value="bar")) # value=<EnumValues.BAR: 'bar'> id=None
try:
print(Table(value="baz")) # id=None
except ValidationError as e:
print(e) # NEVER REACHED
Description
- make a instance of the TableModel which is a pure pydantic model with a valid string in the enum -> success (as it should be)
- make a instance of the TableModel which is a pure pydantic model with an invalid string in the enum -> error (as it should be)
- make a instance of the TableBase which is not
table=True with a valid string in the enum -> success (as it should be)
- make a instance of the TableBase which is not
table=True with an invalid string in the enum -> error (as it should be)
- make a instance of the Table which is
table=True with a valid string in the enum -> success (as it should be)
- make a instance of the Table which is
table=True with an invalid string in the enum -> success (should be error, but creates an instance which is totally missing the non-optional and non-default value field)
Operating System
Linux
Operating System Details
Ubuntu
SQLModel Version
0.0.6
Python Version
3.10.4
Additional Context
No response
First Check
EDIT: See #406 (comment)
Commit to Help
Example Code
Description
table=Truewith a valid string in the enum -> success (as it should be)table=Truewith an invalid string in the enum -> error (as it should be)table=Truewith a valid string in the enum -> success (as it should be)table=Truewith an invalid string in the enum -> success (should be error, but creates an instance which is totally missing the non-optional and non-defaultvaluefield)Operating System
Linux
Operating System Details
Ubuntu
SQLModel Version
0.0.6
Python Version
3.10.4
Additional Context
No response