model_validate problem on Optional attribute using Field() #825
-
First Check
Commit to Help
Example Codeimport decimal
from typing import Annotated, Optional
from sqlmodel import Field, SQLModel
raw_data = {
"c": decimal.Decimal("2.1"),
"d": None,
}
# suggested by https://github.com/pydantic/pydantic/issues/7546
# produces exception TypeError: issubclass() arg 1 must be a class
# in sqlmodel/main.py line 567, in get_sqlalchemy_type
class TestTableProblem(SQLModel, table=True):
id: Optional[int] = Field(default=None, primary_key=True)
c: decimal.Decimal
d: Annotated[decimal.Decimal, Field(max_digits=20, decimal_places=10, nullable=True)] | None
TestTableProblem.model_validate(raw_data) DescriptionI'm using following features:
when specifying attr like Operating SystemLinux, macOS Operating System Detailsrunning it on docker with
SQLModel Version0.0.16 Python Version3.10.12 Additional Context |
Beta Was this translation helpful? Give feedback.
Answered by
YuriiMotov
Aug 21, 2025
Replies: 1 comment
-
d: Annotated[decimal.Decimal | None, Field(max_digits=20, decimal_places=10, nullable=True)] The above works (move
|
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
YuriiMotov
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The above works (move
| None
insideAnnotated
)