]> git.ipfire.org Git - thirdparty/fastapi/fastapi.git/commitdiff
📝 Update Request Body's `tutorial002` to deal with `tax=0` case (#13230)
authorYsabel <5388340+togogh@users.noreply.github.com>
Thu, 30 Jan 2025 12:19:10 +0000 (20:19 +0800)
committerGitHub <noreply@github.com>
Thu, 30 Jan 2025 12:19:10 +0000 (12:19 +0000)
Co-authored-by: svlandeg <svlandeg@github.com>
docs_src/body/tutorial002.py
docs_src/body/tutorial002_py310.py

index 7f51839082d9dc39fa3eefeb48fa14a153547cc5..5cd86216b3904ce92542fef851d3d3e47b412a94 100644 (file)
@@ -17,7 +17,7 @@ app = FastAPI()
 @app.post("/items/")
 async def create_item(item: Item):
     item_dict = item.dict()
-    if item.tax:
+    if item.tax is not None:
         price_with_tax = item.price + item.tax
         item_dict.update({"price_with_tax": price_with_tax})
     return item_dict
index 8928b72b8d2c9d421a52080054fb0eee89efedcb..454c45c886bd0365edf55192b47ee812413ae59c 100644 (file)
@@ -15,7 +15,7 @@ app = FastAPI()
 @app.post("/items/")
 async def create_item(item: Item):
     item_dict = item.dict()
-    if item.tax:
+    if item.tax is not None:
         price_with_tax = item.price + item.tax
         item_dict.update({"price_with_tax": price_with_tax})
     return item_dict