Coverage for tests/test_update.py: 100%

11 statements  

« prev     ^ index     » next       coverage.py v7.17.2, created at 2026-11-16 00:02 +0000

1from sqlmodel import Field, SQLModel 1nopqrstuvwxyz

2 

3 

4def test_sqlmodel_update(): 1nopqrstuvwxyz

5 class Organization(SQLModel, table=True): 1abcdefghijklm

6 id: int = Field(default=None, primary_key=True) 1abcdefghijklm

7 name: str 1abcdefghijklm

8 headquarters: str 1abcdefghijklm

9 

10 class OrganizationUpdate(SQLModel): 1abcdefghijklm

11 name: str 1abcdefghijklm

12 

13 org = Organization(name="Example Org", city="New York", headquarters="NYC HQ") 1abcdefghijklm

14 org_in = OrganizationUpdate(name="Updated org") 1abcdefghijklm

15 org.sqlmodel_update( 1abcdefghijklm

16 org_in, 

17 update={ 

18 "headquarters": "-", # This field is in Organization, but not in OrganizationUpdate 

19 }, 

20 )