Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change status code from 400 to 409 in docs_src /app_testing/ #11263

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sangwoonoel
Copy link

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
image

test_main.py
image

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.

@tiangolo
Copy link
Owner

tiangolo commented Mar 9, 2024

📝 Docs preview for commit 552e927 at: https://15743bed.fastapitiangolo.pages.dev

@alejsdev alejsdev added docs Documentation about how to use FastAPI p3 labels Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation about how to use FastAPI p3
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants