add model_dump options to sqlmodel_update#1897
Open
A00474880 wants to merge 3 commits intofastapi:mainfrom
Open
add model_dump options to sqlmodel_update#1897A00474880 wants to merge 3 commits intofastapi:mainfrom
A00474880 wants to merge 3 commits intofastapi:mainfrom
Conversation
Author
|
I can't seem to be able to add labels to this PR. So it'd be great if I can get this reviewed |
YuriiMotov
reviewed
May 6, 2026
Member
YuriiMotov
left a comment
There was a problem hiding this comment.
@A00474880, thanks for your interest and efforts!
I pointed to a couple of issues with this implementation
| obj: builtins.dict[str, Any] | BaseModel, | ||
| *, | ||
| update: builtins.dict[str, Any] | None = None, | ||
| **model_dump_kwargs, |
Member
There was a problem hiding this comment.
kwargs will not give autocompletion, and it's error-prone
Comment on lines
+994
to
+995
| if isinstance(obj, BaseModel): | ||
| obj = obj.model_dump(**model_dump_kwargs) |
Member
There was a problem hiding this comment.
This will break use cases with models that have fields with exclude=True:
from sqlmodel import Field, SQLModel
class Item(SQLModel):
id: str
param: str = Field(exclude=True)
a = Item.model_validate({"id": "1", "param": "1"})
b = Item.model_validate({"id": "1", "param": "2"})
a.sqlmodel_update(b, exclude={"id"})
# a.sqlmodel_update(b)
assert a.param == "2"
.. and probably some other cases when model has settings that change the default serialization schema.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
As per discussion #1838, this PR allows users to use
model_dumpparameters directly insqlmodel_updatefunction.New Usage Pattern
Previous recommend use of
sqlmodel_updateis as follows:This PR allows the following while keeping backward compatibility with the above:
Tests
This PR also adds assertions in the
test_updatefunction that increases test coverage by 2 lines:before:
after: