From dcc6082c6e47135f799398915a60348f742cc814 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joel=20P=C3=A9rez=20Izquierdo?= Date: Wed, 25 Sep 2024 19:43:25 +0200 Subject: [PATCH 1/2] change old setattr() for db_hero.sqlmodel_update()) --- docs_src/tutorial/fastapi/app_testing/tutorial001/main.py | 3 +-- .../tutorial/fastapi/app_testing/tutorial001_py310/main.py | 3 +-- .../tutorial/fastapi/app_testing/tutorial001_py39/main.py | 3 +-- docs_src/tutorial/fastapi/delete/tutorial001.py | 3 +-- docs_src/tutorial/fastapi/delete/tutorial001_py310.py | 3 +-- docs_src/tutorial/fastapi/delete/tutorial001_py39.py | 3 +-- docs_src/tutorial/fastapi/relationships/tutorial001.py | 6 ++---- .../tutorial/fastapi/relationships/tutorial001_py310.py | 6 ++---- docs_src/tutorial/fastapi/relationships/tutorial001_py39.py | 6 ++---- .../tutorial/fastapi/session_with_dependency/tutorial001.py | 3 +-- .../fastapi/session_with_dependency/tutorial001_py310.py | 3 +-- .../fastapi/session_with_dependency/tutorial001_py39.py | 3 +-- docs_src/tutorial/fastapi/teams/tutorial001.py | 6 ++---- docs_src/tutorial/fastapi/teams/tutorial001_py310.py | 6 ++---- docs_src/tutorial/fastapi/teams/tutorial001_py39.py | 6 ++---- 15 files changed, 21 insertions(+), 42 deletions(-) diff --git a/docs_src/tutorial/fastapi/app_testing/tutorial001/main.py b/docs_src/tutorial/fastapi/app_testing/tutorial001/main.py index f46d8b078e..f0a2559467 100644 --- a/docs_src/tutorial/fastapi/app_testing/tutorial001/main.py +++ b/docs_src/tutorial/fastapi/app_testing/tutorial001/main.py @@ -88,8 +88,7 @@ def update_hero( if not db_hero: raise HTTPException(status_code=404, detail="Hero not found") hero_data = hero.model_dump(exclude_unset=True) - for key, value in hero_data.items(): - setattr(db_hero, key, value) + db_hero.sqlmodel_update(hero_data) session.add(db_hero) session.commit() session.refresh(db_hero) diff --git a/docs_src/tutorial/fastapi/app_testing/tutorial001_py310/main.py b/docs_src/tutorial/fastapi/app_testing/tutorial001_py310/main.py index 702eba722b..84da9fd610 100644 --- a/docs_src/tutorial/fastapi/app_testing/tutorial001_py310/main.py +++ b/docs_src/tutorial/fastapi/app_testing/tutorial001_py310/main.py @@ -86,8 +86,7 @@ def update_hero( if not db_hero: raise HTTPException(status_code=404, detail="Hero not found") hero_data = hero.model_dump(exclude_unset=True) - for key, value in hero_data.items(): - setattr(db_hero, key, value) + db_hero.sqlmodel_update(hero_data) session.add(db_hero) session.commit() session.refresh(db_hero) diff --git a/docs_src/tutorial/fastapi/app_testing/tutorial001_py39/main.py b/docs_src/tutorial/fastapi/app_testing/tutorial001_py39/main.py index efdfd8ee6c..e7371d84e3 100644 --- a/docs_src/tutorial/fastapi/app_testing/tutorial001_py39/main.py +++ b/docs_src/tutorial/fastapi/app_testing/tutorial001_py39/main.py @@ -88,8 +88,7 @@ def update_hero( if not db_hero: raise HTTPException(status_code=404, detail="Hero not found") hero_data = hero.model_dump(exclude_unset=True) - for key, value in hero_data.items(): - setattr(db_hero, key, value) + db_hero.sqlmodel_update(hero_data) session.add(db_hero) session.commit() session.refresh(db_hero) diff --git a/docs_src/tutorial/fastapi/delete/tutorial001.py b/docs_src/tutorial/fastapi/delete/tutorial001.py index 1871ab1707..977882c4c2 100644 --- a/docs_src/tutorial/fastapi/delete/tutorial001.py +++ b/docs_src/tutorial/fastapi/delete/tutorial001.py @@ -80,8 +80,7 @@ def update_hero(hero_id: int, hero: HeroUpdate): if not db_hero: raise HTTPException(status_code=404, detail="Hero not found") hero_data = hero.model_dump(exclude_unset=True) - for key, value in hero_data.items(): - setattr(db_hero, key, value) + db_hero.sqlmodel_update(hero_data) session.add(db_hero) session.commit() session.refresh(db_hero) diff --git a/docs_src/tutorial/fastapi/delete/tutorial001_py310.py b/docs_src/tutorial/fastapi/delete/tutorial001_py310.py index 0dd0c889fa..f7de4019d2 100644 --- a/docs_src/tutorial/fastapi/delete/tutorial001_py310.py +++ b/docs_src/tutorial/fastapi/delete/tutorial001_py310.py @@ -78,8 +78,7 @@ def update_hero(hero_id: int, hero: HeroUpdate): if not db_hero: raise HTTPException(status_code=404, detail="Hero not found") hero_data = hero.model_dump(exclude_unset=True) - for key, value in hero_data.items(): - setattr(db_hero, key, value) + db_hero.sqlmodel_update(hero_data) session.add(db_hero) session.commit() session.refresh(db_hero) diff --git a/docs_src/tutorial/fastapi/delete/tutorial001_py39.py b/docs_src/tutorial/fastapi/delete/tutorial001_py39.py index 9ab3056c82..5d5f099abb 100644 --- a/docs_src/tutorial/fastapi/delete/tutorial001_py39.py +++ b/docs_src/tutorial/fastapi/delete/tutorial001_py39.py @@ -80,8 +80,7 @@ def update_hero(hero_id: int, hero: HeroUpdate): if not db_hero: raise HTTPException(status_code=404, detail="Hero not found") hero_data = hero.model_dump(exclude_unset=True) - for key, value in hero_data.items(): - setattr(db_hero, key, value) + db_hero.sqlmodel_update(hero_data) session.add(db_hero) session.commit() session.refresh(db_hero) diff --git a/docs_src/tutorial/fastapi/relationships/tutorial001.py b/docs_src/tutorial/fastapi/relationships/tutorial001.py index ac8a557cfc..59b44730ba 100644 --- a/docs_src/tutorial/fastapi/relationships/tutorial001.py +++ b/docs_src/tutorial/fastapi/relationships/tutorial001.py @@ -126,8 +126,7 @@ def update_hero( if not db_hero: raise HTTPException(status_code=404, detail="Hero not found") hero_data = hero.model_dump(exclude_unset=True) - for key, value in hero_data.items(): - setattr(db_hero, key, value) + db_hero.sqlmodel_update(hero_data) session.add(db_hero) session.commit() session.refresh(db_hero) @@ -183,8 +182,7 @@ def update_team( if not db_team: raise HTTPException(status_code=404, detail="Team not found") team_data = team.model_dump(exclude_unset=True) - for key, value in team_data.items(): - setattr(db_team, key, value) + db_team.sqlmodel_update(team_data) session.add(db_team) session.commit() session.refresh(db_team) diff --git a/docs_src/tutorial/fastapi/relationships/tutorial001_py310.py b/docs_src/tutorial/fastapi/relationships/tutorial001_py310.py index 5110b158b0..47c2e5f0bc 100644 --- a/docs_src/tutorial/fastapi/relationships/tutorial001_py310.py +++ b/docs_src/tutorial/fastapi/relationships/tutorial001_py310.py @@ -124,8 +124,7 @@ def update_hero( if not db_hero: raise HTTPException(status_code=404, detail="Hero not found") hero_data = hero.model_dump(exclude_unset=True) - for key, value in hero_data.items(): - setattr(db_hero, key, value) + db_hero.sqlmodel_update(hero_data) session.add(db_hero) session.commit() session.refresh(db_hero) @@ -181,8 +180,7 @@ def update_team( if not db_team: raise HTTPException(status_code=404, detail="Team not found") team_data = team.model_dump(exclude_unset=True) - for key, value in team_data.items(): - setattr(db_team, key, value) + db_team.sqlmodel_update(team_data) session.add(db_team) session.commit() session.refresh(db_team) diff --git a/docs_src/tutorial/fastapi/relationships/tutorial001_py39.py b/docs_src/tutorial/fastapi/relationships/tutorial001_py39.py index a4e953c4d7..1cfa298b8b 100644 --- a/docs_src/tutorial/fastapi/relationships/tutorial001_py39.py +++ b/docs_src/tutorial/fastapi/relationships/tutorial001_py39.py @@ -126,8 +126,7 @@ def update_hero( if not db_hero: raise HTTPException(status_code=404, detail="Hero not found") hero_data = hero.model_dump(exclude_unset=True) - for key, value in hero_data.items(): - setattr(db_hero, key, value) + db_hero.sqlmodel_update(hero_data) session.add(db_hero) session.commit() session.refresh(db_hero) @@ -183,8 +182,7 @@ def update_team( if not db_team: raise HTTPException(status_code=404, detail="Team not found") team_data = team.model_dump(exclude_unset=True) - for key, value in team_data.items(): - setattr(db_team, key, value) + db_team.sqlmodel_update(team_data) session.add(db_team) session.commit() session.refresh(db_team) diff --git a/docs_src/tutorial/fastapi/session_with_dependency/tutorial001.py b/docs_src/tutorial/fastapi/session_with_dependency/tutorial001.py index f46d8b078e..f0a2559467 100644 --- a/docs_src/tutorial/fastapi/session_with_dependency/tutorial001.py +++ b/docs_src/tutorial/fastapi/session_with_dependency/tutorial001.py @@ -88,8 +88,7 @@ def update_hero( if not db_hero: raise HTTPException(status_code=404, detail="Hero not found") hero_data = hero.model_dump(exclude_unset=True) - for key, value in hero_data.items(): - setattr(db_hero, key, value) + db_hero.sqlmodel_update(hero_data) session.add(db_hero) session.commit() session.refresh(db_hero) diff --git a/docs_src/tutorial/fastapi/session_with_dependency/tutorial001_py310.py b/docs_src/tutorial/fastapi/session_with_dependency/tutorial001_py310.py index 702eba722b..84da9fd610 100644 --- a/docs_src/tutorial/fastapi/session_with_dependency/tutorial001_py310.py +++ b/docs_src/tutorial/fastapi/session_with_dependency/tutorial001_py310.py @@ -86,8 +86,7 @@ def update_hero( if not db_hero: raise HTTPException(status_code=404, detail="Hero not found") hero_data = hero.model_dump(exclude_unset=True) - for key, value in hero_data.items(): - setattr(db_hero, key, value) + db_hero.sqlmodel_update(hero_data) session.add(db_hero) session.commit() session.refresh(db_hero) diff --git a/docs_src/tutorial/fastapi/session_with_dependency/tutorial001_py39.py b/docs_src/tutorial/fastapi/session_with_dependency/tutorial001_py39.py index efdfd8ee6c..e7371d84e3 100644 --- a/docs_src/tutorial/fastapi/session_with_dependency/tutorial001_py39.py +++ b/docs_src/tutorial/fastapi/session_with_dependency/tutorial001_py39.py @@ -88,8 +88,7 @@ def update_hero( if not db_hero: raise HTTPException(status_code=404, detail="Hero not found") hero_data = hero.model_dump(exclude_unset=True) - for key, value in hero_data.items(): - setattr(db_hero, key, value) + db_hero.sqlmodel_update(hero_data) session.add(db_hero) session.commit() session.refresh(db_hero) diff --git a/docs_src/tutorial/fastapi/teams/tutorial001.py b/docs_src/tutorial/fastapi/teams/tutorial001.py index 4289221ff5..49dd83065a 100644 --- a/docs_src/tutorial/fastapi/teams/tutorial001.py +++ b/docs_src/tutorial/fastapi/teams/tutorial001.py @@ -117,8 +117,7 @@ def update_hero( if not db_hero: raise HTTPException(status_code=404, detail="Hero not found") hero_data = hero.model_dump(exclude_unset=True) - for key, value in hero_data.items(): - setattr(db_hero, key, value) + db_hero.sqlmodel_update(hero_data) session.add(db_hero) session.commit() session.refresh(db_hero) @@ -174,8 +173,7 @@ def update_team( if not db_team: raise HTTPException(status_code=404, detail="Team not found") team_data = team.model_dump(exclude_unset=True) - for key, value in team_data.items(): - setattr(db_team, key, value) + db_team.sqlmodel_update(team_data) session.add(db_team) session.commit() session.refresh(db_team) diff --git a/docs_src/tutorial/fastapi/teams/tutorial001_py310.py b/docs_src/tutorial/fastapi/teams/tutorial001_py310.py index 630ae4f98a..b78f059e12 100644 --- a/docs_src/tutorial/fastapi/teams/tutorial001_py310.py +++ b/docs_src/tutorial/fastapi/teams/tutorial001_py310.py @@ -115,8 +115,7 @@ def update_hero( if not db_hero: raise HTTPException(status_code=404, detail="Hero not found") hero_data = hero.model_dump(exclude_unset=True) - for key, value in hero_data.items(): - setattr(db_hero, key, value) + db_hero.sqlmodel_update(hero_data) session.add(db_hero) session.commit() session.refresh(db_hero) @@ -172,8 +171,7 @@ def update_team( if not db_team: raise HTTPException(status_code=404, detail="Team not found") team_data = team.model_dump(exclude_unset=True) - for key, value in team_data.items(): - setattr(db_team, key, value) + db_team.sqlmodel_update(team_data) session.add(db_team) session.commit() session.refresh(db_team) diff --git a/docs_src/tutorial/fastapi/teams/tutorial001_py39.py b/docs_src/tutorial/fastapi/teams/tutorial001_py39.py index 661e435373..928ec70976 100644 --- a/docs_src/tutorial/fastapi/teams/tutorial001_py39.py +++ b/docs_src/tutorial/fastapi/teams/tutorial001_py39.py @@ -117,8 +117,7 @@ def update_hero( if not db_hero: raise HTTPException(status_code=404, detail="Hero not found") hero_data = hero.model_dump(exclude_unset=True) - for key, value in hero_data.items(): - setattr(db_hero, key, value) + db_hero.sqlmodel_update(hero_data) session.add(db_hero) session.commit() session.refresh(db_hero) @@ -174,8 +173,7 @@ def update_team( if not db_team: raise HTTPException(status_code=404, detail="Team not found") team_data = team.model_dump(exclude_unset=True) - for key, value in team_data.items(): - setattr(db_team, key, value) + db_team.sqlmodel_update(team_data) session.add(db_team) session.commit() session.refresh(db_team) From 507b5fda9cda644243f7daf1e393683814518249 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joel=20P=C3=A9rez=20Izquierdo?= Date: Wed, 25 Sep 2024 23:22:11 +0200 Subject: [PATCH 2/2] update the name of the test shell script --- docs/contributing.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/contributing.md b/docs/contributing.md index e3693c5a8d..8228bc4132 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -63,7 +63,7 @@ There is a script that you can run locally to test all the code and generate cov
```console -$ bash scripts/test-cov-html.sh +$ bash scripts/test.sh ```