Uh oh!
There was an error while loading. Please reload this page.
SQLModel give fastapi incomplete pydantic model if generic is used in response_model. #1668
First Check
Commit to Help
Example CodefromtypingimportGeneric, TypeVarfromfastapiimportFastAPIfromsqlmodelimportSQLModelT=TypeVar("T")
app=FastAPI()
classUser(SQLModel):
name: strclassUserInternal(SQLModel):
name: strhashed_password: strclassAppResponse(SQLModel, Generic[T]):
data: T|None=Nonecode: int=200message: str="success"@app.get("/", response_model=AppResponse[User])defget_user():
db_user=UserInternal(name="John Doe", hashed_password="hashed_secret")
returnAppResponse(data=db_user)
if__name__=="__main__":
importuvicornuvicorn.run(app, host="127.0.0.1", port=8001)DescriptionReproduce
It seems that SQLModel won't give fastapi correct pydantic model if generic is used. Operating SystemWindows Operating System DetailsNo response SQLModel Version0.0.27 Python VersionPython 3.13.9 Additional Context![]() |
Answered by
YuriiMotov
Dec 6, 2025
Replies: 1 comment
There is PR #1275 to fix this. I checked, your code example works well on the branch of that PR |
0 replies
Answer selected byTrueRou
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment

There is PR #1275 to fix this.
I checked, your code example works well on the branch of that PR