-
-
Notifications
You must be signed in to change notification settings - Fork 296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: SQLModel table model not validated #1696
base: main
Are you sure you want to change the base?
fix: SQLModel table model not validated #1696
Conversation
ce0553f
to
9935ffe
Compare
thanks @AlpAribal do you mind rebasing these changes onto the |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1696 +/- ##
==========================================
- Coverage 94.28% 93.55% -0.73%
==========================================
Files 91 117 +26
Lines 7013 8843 +1830
==========================================
+ Hits 6612 8273 +1661
- Misses 401 570 +169 ☔ View full report in Codecov by Sentry. |
9935ffe
to
39451bc
Compare
linter is making some valid complaints:
You might have to do something like: try:
_type = typing.cast(Type[BaseModel], self.type)
# pylint: disable=not-callable
if PYDANTIC_V2:
row = self.type.model_validate(row).model_dump()
else:
row = self.type.parse_obj(row).dict() |
6e15ee3
to
a61a828
Compare
Unfortunately, casting did not work, pylint still complains. This SO answer hints that pylint discards the type hint and uses the actual value ( |
@AlpAribal I'm okay with ignoring the pylint warning |
13198fc
to
d5b7608
Compare
Signed-off-by: Alp Aribal <[email protected]>
Signed-off-by: Alp Aribal <[email protected]>
Signed-off-by: Alp Aribal <[email protected]>
Signed-off-by: Alp Aribal <[email protected]>
Signed-off-by: Alp Aribal <[email protected]>
d5b7608
to
59e7f30
Compare
When using a SQLModel class with
table=True
asdtype
, schema is not validated. This is because such SQLModel classes do not validate data at init time (see here). This PR solves this by explicitly callingmodel_validate
/parse_obj
instead of instantiating the class.Minimal example (
python=3.8 sqlmodel=0.0.19 pandera=0.19.3
):Without the fix, validation succeeds while only emitting a warning from
model_dump()
:With the fix, a SchemaError is raised: