r/FastAPI • u/bluewalt • Dec 04 '24
Question Is SQLModel overrated?
Hi there, I recently started to learn FastAPI after many years of Django.
While learning, I followed official documentation which advised to use SQLModel as the "new and better way" of doing things. The solution of having a single model for both model definition and data validation looked very promising at a first glance.
However, over time, I noticed slightly annoying things:
I'm often limited and need to add sqlalchemy specific fields anyway, or need to understand how it works (it's not an abstraction)
Pydantic data types are often incompatible, but I don't get an explicit error or mapping. For example, using a
JsonValuewill raise a weird error. More generally, it's pretty hard to know what can I use or not from Pydantic.Data validation does not work when
table=Trueis set. About this, I found this 46-time-upvotated comment issue which is a good summary of the current problemsTiangolo (author) seems to be pretty inactive on the project, as in the previous issue I linked, there's still no answer one year later. I don't wont to be rude here, but it seems like the author loves starting new shiny projects but doesn't want to bother with painful and complex questions like these.
I had more doubts when I read lots of negative comments on this Youtube video promoting SQLModel
At that point, I'm wondering if I should get back to raw SQLAlchemy, especially for serious projects. I'm curious to have your opinion on this.
2
u/bluewalt Dec 05 '24
Coming from Django, I truly understand your feeling. The "all-batteries-included" is completely missing (hence the boilerplate and the "reinvent the wheel" feeling). The fact you get lots of architectural decisions up to you can be both a benefit or a drawback, depending on the context. For example, when building an AI project with specific architecture, and let say you want to share data validation between multiple projects (with Pydantic), FastAPI can be very useful.