Replies: 2 comments
|
I investigated this issue and implemented a solution locally. I added support for the extra parameter in the model_validate and the sqlmodel_validate function since the underlying ExtraBehaviour is already implemented in Core Schema. Also created a test to run a verification covering the issue. Before opening a PR, just wanted to check whether this is the intended approach in this matter. |
|
Hey, just looked into this — the issue is straightforward. SQLModel's model_validate in main.py and sqlmodel_validate in _compat.py both accept strict, from_attributes, context, and update, but extra got left out even though @RandhawaP2005 your approach sounds right to me! You'd need to touch two spots: sqlmodel/main.py — add extra to the signature and pass it down: And the same in _compat.py — add extra to sqlmodel_validate and pass it into the validate_python() call. Literal is already imported so no new deps needed. Would love to see a PR on this, seems like a clean fix! |
Uh oh!
There was an error while loading. Please reload this page.
First Check
Commit to Help
Example Code
Description
The parameter
extrais supported in the pydanticmodel_validate():https://docs.pydantic.dev/latest/api/base_model/#pydantic.BaseModel.model_validate
But that parameter is not supported in sqlmodel due to that method being overridden:
https://github.com/fastapi/sqlmodel/blob/main/sqlmodel/main.py#L873
https://github.com/fastapi/sqlmodel/blob/main/sqlmodel/_compat.py#L276
The
validate_python()method already takesextra, so this should be a simple fix.I can take a look at a PR if that would be helpful.
Operating System
macOS
Operating System Details
No response
SQLModel Version
0.0.37
Python Version
Python 3.11.14
Additional Context
No response
All reactions