Replies: 1 comment
-
After going through the docs a lot more, it looks like the suggestion is to create data models and return those, while using the table models inside the routes, only. This does fix the issue since the data models never directly access the db, but it's very unclear why using the db model directly, is causing the explained issue. One place in the docs it actually said that you could return the table model directly if you wanted to, but never mentions this issue which makes me think it's a bug. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
First Check
Commit to Help
Example Code
Description
Testing Steps:
curl http://127.0.0.1:8000/debug
return customer
toreturn customer.model_dump()
When the SQLModel is returned directly and response_model is set, I would expect the JSON response to return in the field order of the response_model, but it's not. The order returned is the same as it prints before the return (I'm assuming this is how it's selected from the database).
With
return customer
:With
return customer.model_dump()
(what I would have expected when returning customer directly):What's weirder, if I copy the Customer class to Customer2 and set response_model to Customer2, response_model ordering is honored!! It's exactly the same code!!!!!
Something is going on internally where when SQL is executed on a model, the ordering breaks on any future usage.
Operating System
Linux
Operating System Details
My development is taking place in python:3 docker container running in a WSL Ubuntu distro.
SQLModel Version
0.0.22
Python Version
Python 3.12.7
Additional Context
Thank you for developing these tools. They are really interesting and I'm excited to keep using both in my day to day workflow!
Beta Was this translation helpful? Give feedback.
All reactions