fastapi
fastapi copied to clipboard
Change status code from 400 to 409 in docs_src /app_testing/
I consistently changed the status code in docs_src/app_testing/ from 400 to 409. Previously, it was inconsistently set to 400 in some places and 409 in others.
I believe that 409 is more appropriate than 400 for cases where the item already exists, as it indicates a resource conflict.
before
if item.id in fake_db:
raise HTTPException(status_code=400, detail="Item already exists")
after
if item.id in fake_db:
raise HTTPException(status_code=409, detail="Item already exists")
While working on a project using FastAPI and referring to the Documentation for writing test code, I encountered confusion due to the inconsistent status codes in the testing tutorial at https://fastapi.tiangolo.com/tutorial/testing/.
main.py
test_main.py
The documentation for Python 3.10+, Python 3.9+, and Python 3.8+ lists a status code of 400, whereas for Python 3.10+ non-Annotated and Python 3.8+ non-Annotated, it lists a status code of 409. However, in test_main.py, the status code is 409.
📝 Docs preview for commit 552e927686064c8ec21b448c3da0be6e27f2904d at: https://15743bed.fastapitiangolo.pages.dev