Skip to content

Commit dcc6082

Browse files
committed
change old setattr() for db_hero.sqlmodel_update())
1 parent 7dbd1a9 commit dcc6082

File tree

15 files changed

+21
-42
lines changed

15 files changed

+21
-42
lines changed

docs_src/tutorial/fastapi/app_testing/tutorial001/main.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,7 @@ def update_hero(
8888
if not db_hero:
8989
raise HTTPException(status_code=404, detail="Hero not found")
9090
hero_data = hero.model_dump(exclude_unset=True)
91-
for key, value in hero_data.items():
92-
setattr(db_hero, key, value)
91+
db_hero.sqlmodel_update(hero_data)
9392
session.add(db_hero)
9493
session.commit()
9594
session.refresh(db_hero)

docs_src/tutorial/fastapi/app_testing/tutorial001_py310/main.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ def update_hero(
8686
if not db_hero:
8787
raise HTTPException(status_code=404, detail="Hero not found")
8888
hero_data = hero.model_dump(exclude_unset=True)
89-
for key, value in hero_data.items():
90-
setattr(db_hero, key, value)
89+
db_hero.sqlmodel_update(hero_data)
9190
session.add(db_hero)
9291
session.commit()
9392
session.refresh(db_hero)

docs_src/tutorial/fastapi/app_testing/tutorial001_py39/main.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,7 @@ def update_hero(
8888
if not db_hero:
8989
raise HTTPException(status_code=404, detail="Hero not found")
9090
hero_data = hero.model_dump(exclude_unset=True)
91-
for key, value in hero_data.items():
92-
setattr(db_hero, key, value)
91+
db_hero.sqlmodel_update(hero_data)
9392
session.add(db_hero)
9493
session.commit()
9594
session.refresh(db_hero)

docs_src/tutorial/fastapi/delete/tutorial001.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ def update_hero(hero_id: int, hero: HeroUpdate):
8080
if not db_hero:
8181
raise HTTPException(status_code=404, detail="Hero not found")
8282
hero_data = hero.model_dump(exclude_unset=True)
83-
for key, value in hero_data.items():
84-
setattr(db_hero, key, value)
83+
db_hero.sqlmodel_update(hero_data)
8584
session.add(db_hero)
8685
session.commit()
8786
session.refresh(db_hero)

docs_src/tutorial/fastapi/delete/tutorial001_py310.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ def update_hero(hero_id: int, hero: HeroUpdate):
7878
if not db_hero:
7979
raise HTTPException(status_code=404, detail="Hero not found")
8080
hero_data = hero.model_dump(exclude_unset=True)
81-
for key, value in hero_data.items():
82-
setattr(db_hero, key, value)
81+
db_hero.sqlmodel_update(hero_data)
8382
session.add(db_hero)
8483
session.commit()
8584
session.refresh(db_hero)

docs_src/tutorial/fastapi/delete/tutorial001_py39.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ def update_hero(hero_id: int, hero: HeroUpdate):
8080
if not db_hero:
8181
raise HTTPException(status_code=404, detail="Hero not found")
8282
hero_data = hero.model_dump(exclude_unset=True)
83-
for key, value in hero_data.items():
84-
setattr(db_hero, key, value)
83+
db_hero.sqlmodel_update(hero_data)
8584
session.add(db_hero)
8685
session.commit()
8786
session.refresh(db_hero)

docs_src/tutorial/fastapi/relationships/tutorial001.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,7 @@ def update_hero(
126126
if not db_hero:
127127
raise HTTPException(status_code=404, detail="Hero not found")
128128
hero_data = hero.model_dump(exclude_unset=True)
129-
for key, value in hero_data.items():
130-
setattr(db_hero, key, value)
129+
db_hero.sqlmodel_update(hero_data)
131130
session.add(db_hero)
132131
session.commit()
133132
session.refresh(db_hero)
@@ -183,8 +182,7 @@ def update_team(
183182
if not db_team:
184183
raise HTTPException(status_code=404, detail="Team not found")
185184
team_data = team.model_dump(exclude_unset=True)
186-
for key, value in team_data.items():
187-
setattr(db_team, key, value)
185+
db_team.sqlmodel_update(team_data)
188186
session.add(db_team)
189187
session.commit()
190188
session.refresh(db_team)

docs_src/tutorial/fastapi/relationships/tutorial001_py310.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,7 @@ def update_hero(
124124
if not db_hero:
125125
raise HTTPException(status_code=404, detail="Hero not found")
126126
hero_data = hero.model_dump(exclude_unset=True)
127-
for key, value in hero_data.items():
128-
setattr(db_hero, key, value)
127+
db_hero.sqlmodel_update(hero_data)
129128
session.add(db_hero)
130129
session.commit()
131130
session.refresh(db_hero)
@@ -181,8 +180,7 @@ def update_team(
181180
if not db_team:
182181
raise HTTPException(status_code=404, detail="Team not found")
183182
team_data = team.model_dump(exclude_unset=True)
184-
for key, value in team_data.items():
185-
setattr(db_team, key, value)
183+
db_team.sqlmodel_update(team_data)
186184
session.add(db_team)
187185
session.commit()
188186
session.refresh(db_team)

docs_src/tutorial/fastapi/relationships/tutorial001_py39.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,7 @@ def update_hero(
126126
if not db_hero:
127127
raise HTTPException(status_code=404, detail="Hero not found")
128128
hero_data = hero.model_dump(exclude_unset=True)
129-
for key, value in hero_data.items():
130-
setattr(db_hero, key, value)
129+
db_hero.sqlmodel_update(hero_data)
131130
session.add(db_hero)
132131
session.commit()
133132
session.refresh(db_hero)
@@ -183,8 +182,7 @@ def update_team(
183182
if not db_team:
184183
raise HTTPException(status_code=404, detail="Team not found")
185184
team_data = team.model_dump(exclude_unset=True)
186-
for key, value in team_data.items():
187-
setattr(db_team, key, value)
185+
db_team.sqlmodel_update(team_data)
188186
session.add(db_team)
189187
session.commit()
190188
session.refresh(db_team)

docs_src/tutorial/fastapi/session_with_dependency/tutorial001.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,7 @@ def update_hero(
8888
if not db_hero:
8989
raise HTTPException(status_code=404, detail="Hero not found")
9090
hero_data = hero.model_dump(exclude_unset=True)
91-
for key, value in hero_data.items():
92-
setattr(db_hero, key, value)
91+
db_hero.sqlmodel_update(hero_data)
9392
session.add(db_hero)
9493
session.commit()
9594
session.refresh(db_hero)

0 commit comments

Comments
 (0)