File tree Expand file tree Collapse file tree 2 files changed +21
-2
lines changed
Expand file tree Collapse file tree 2 files changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -1004,9 +1004,8 @@ def sqlmodel_update(
10041004 else :
10051005 value = getattr (obj , key )
10061006 setattr (self , key , value )
1007- for remaining_key in use_update :
1007+ for remaining_key , value in use_update . items () :
10081008 if remaining_key in get_model_fields (self ):
1009- value = use_update .pop (remaining_key )
10101009 setattr (self , remaining_key , value )
10111010 else :
10121011 raise ValueError (
Original file line number Diff line number Diff line change 1+ from sqlmodel import Field , SQLModel
2+
3+
4+ def test_sqlmodel_update ():
5+ class Organization (SQLModel , table = True ):
6+ id : int = Field (default = None , primary_key = True )
7+ name : str
8+ headquarters : str
9+
10+ class OrganizationUpdate (SQLModel ):
11+ name : str
12+
13+ org = Organization (name = "Example Org" , city = "New York" , headquarters = "NYC HQ" )
14+ org_in = OrganizationUpdate (name = "Updated org" )
15+ org .sqlmodel_update (
16+ org_in ,
17+ update = {
18+ "headquarters" : "-" , # This field is in Organization, but not in OrganizationUpdate
19+ },
20+ )
You can’t perform that action at this time.
0 commit comments