From 8ab6cfb6c2cfc6255fe0b52cfe50205021e7beab Mon Sep 17 00:00:00 2001 From: "Harsh N. Haria" <31141242+harsh-haria@users.noreply.github.com> Date: Sat, 15 Mar 2025 00:58:35 +0530 Subject: [PATCH 1/2] Updated tutorial002.py dict() is now deprecated. We need to replace it with model_dump() --- docs_src/body/tutorial002.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs_src/body/tutorial002.py b/docs_src/body/tutorial002.py index 5cd86216b..fb212e8e7 100644 --- a/docs_src/body/tutorial002.py +++ b/docs_src/body/tutorial002.py @@ -16,7 +16,7 @@ app = FastAPI() @app.post("/items/") async def create_item(item: Item): - item_dict = item.dict() + item_dict = item.model_dump() if item.tax is not None: price_with_tax = item.price + item.tax item_dict.update({"price_with_tax": price_with_tax}) From 4a7f7e986fee39d10e4e47f768f7312c8c311046 Mon Sep 17 00:00:00 2001 From: Harsh Haria Date: Sun, 23 Mar 2025 15:21:27 +0530 Subject: [PATCH 2/2] updated all the other examples in the docs_src/body to have model_dump() instead of dict() since its deprecated --- docs_src/body/tutorial002_py310.py | 2 +- docs_src/body/tutorial003.py | 2 +- docs_src/body/tutorial003_py310.py | 2 +- docs_src/body/tutorial004.py | 2 +- docs_src/body/tutorial004_py310.py | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs_src/body/tutorial002_py310.py b/docs_src/body/tutorial002_py310.py index 454c45c88..a829a4dc9 100644 --- a/docs_src/body/tutorial002_py310.py +++ b/docs_src/body/tutorial002_py310.py @@ -14,7 +14,7 @@ app = FastAPI() @app.post("/items/") async def create_item(item: Item): - item_dict = item.dict() + item_dict = item.model_dump() if item.tax is not None: price_with_tax = item.price + item.tax item_dict.update({"price_with_tax": price_with_tax}) diff --git a/docs_src/body/tutorial003.py b/docs_src/body/tutorial003.py index 2f33cc038..636ba2275 100644 --- a/docs_src/body/tutorial003.py +++ b/docs_src/body/tutorial003.py @@ -16,4 +16,4 @@ app = FastAPI() @app.put("/items/{item_id}") async def update_item(item_id: int, item: Item): - return {"item_id": item_id, **item.dict()} + return {"item_id": item_id, **item.model_dump()} diff --git a/docs_src/body/tutorial003_py310.py b/docs_src/body/tutorial003_py310.py index 440b210e6..51ac8aafa 100644 --- a/docs_src/body/tutorial003_py310.py +++ b/docs_src/body/tutorial003_py310.py @@ -14,4 +14,4 @@ app = FastAPI() @app.put("/items/{item_id}") async def update_item(item_id: int, item: Item): - return {"item_id": item_id, **item.dict()} + return {"item_id": item_id, **item.model_dump()} diff --git a/docs_src/body/tutorial004.py b/docs_src/body/tutorial004.py index 0671e0a27..2c157abfa 100644 --- a/docs_src/body/tutorial004.py +++ b/docs_src/body/tutorial004.py @@ -16,7 +16,7 @@ app = FastAPI() @app.put("/items/{item_id}") async def update_item(item_id: int, item: Item, q: Union[str, None] = None): - result = {"item_id": item_id, **item.dict()} + result = {"item_id": item_id, **item.model_dump()} if q: result.update({"q": q}) return result diff --git a/docs_src/body/tutorial004_py310.py b/docs_src/body/tutorial004_py310.py index b352b70ab..53b10d97b 100644 --- a/docs_src/body/tutorial004_py310.py +++ b/docs_src/body/tutorial004_py310.py @@ -14,7 +14,7 @@ app = FastAPI() @app.put("/items/{item_id}") async def update_item(item_id: int, item: Item, q: str | None = None): - result = {"item_id": item_id, **item.dict()} + result = {"item_id": item_id, **item.model_dump()} if q: result.update({"q": q}) return result