strict=True breaks date parsing from json (works in pydantic) #816
Unanswered
JacobHayes
asked this question in
Questions
Replies: 2 comments
-
I'm hoping to fix this in #818 |
Beta Was this translation helpful? Give feedback.
0 replies
-
I wonder if there is a relationship of this to #824 |
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
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
SQLModels fails to validate json data with a date field into a model with
model_config = {"strict": True}
. Pydantic validates the same data correctly. For example, here's the output of the script above:I haven't confirmed but my hunch is that SQLModel might be "removing" the quotes around the date string before passing into Pydantic in this case, eg: it's sendingI think it's actually that the'1970-01-01'
instead of valid json like'"1970-01-01"'
.model_validate
method defers to thesqlmodel_validate
compat helper func, which just callscls.__pydantic_validator__.validate_python
instead ofcls.__pydantic_validator__.validate_json
. As noted in the pydantic docs, json validation in strict mode is still a bit more flexible to accommodate the limited json types (eg: no native date, etc).Operating System
macOS
Operating System Details
No response
SQLModel Version
0.0.16
Python Version
Python 3.12.1
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions