BUG: SQLModels with table=True aren't properly restored from JSON #1791
Unanswered
DanielGibson
asked this question in
Questions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
First Check
Commit to Help
Example Code
Description
Basically: For SQLModels with
table=True,model_validate_json(jstr)is broken, and so ismodel_validate( json.loads(jstr) ), but in slightly different ways.model_validate_json(jstr)does not restore non-JSON types (meaning, ones not natively supported by JSON) properly when used with atable=TrueSQLModel.For example, serialized
UUIDanddatetimeobjects remain strings.model_validate( json.loads(jstr) )does restore those types properly when used directly on an SQLModeltable=Truetype, but when that SQLModel is a member of another type it's broken in the same way as the former case (e.g. UUIDs remain strings).Weirdly, for SQLModels with table=False everything seems to work.
Operating System
Linux
Operating System Details
No response
SQLModel Version
0.0.37
Python Version
3.13.9
Additional Context
Of course this issue also creates problems when using affected types with FastAPI.
The output when running the aforementioned code looks like this:
Details
Beta Was this translation helpful? Give feedback.
All reactions