From 4e966ca2ec369444d875c3613a57a4611c47e2fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s=20Planch=C3=B3n=20Prestes?= Date: Mon, 3 Nov 2025 18:11:52 -0300 Subject: [PATCH] Adding note on exceptions.md about falsy values possibly coming from FastCRUD in the future. --- .gitignore | 4 +++- docs/user-guide/api/exceptions.md | 10 +++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 8b1f9b59..ab9ad704 100644 --- a/.gitignore +++ b/.gitignore @@ -132,4 +132,6 @@ cython_debug/ .ruff_cache -.idea \ No newline at end of file +.idea + +.vscode/ diff --git a/docs/user-guide/api/exceptions.md b/docs/user-guide/api/exceptions.md index 9186ff96..d4b9cd7c 100644 --- a/docs/user-guide/api/exceptions.md +++ b/docs/user-guide/api/exceptions.md @@ -63,7 +63,7 @@ from app.core.exceptions.http_exceptions import ForbiddenException async def delete_user( user_id: int, current_user: Annotated[dict, Depends(get_current_user)] -): + ): if current_user["id"] != user_id and not current_user["is_superuser"]: raise ForbiddenException("You can only delete your own account") @@ -121,7 +121,7 @@ async def update_user( user_id: int, user_data: UserUpdate, db: AsyncSession -): + ): # Check if user exists if not await crud_users.exists(db=db, id=user_id): raise NotFoundException("User not found") @@ -143,7 +143,7 @@ async def get_post( post_id: int, current_user: Annotated[dict, Depends(get_current_user)], db: AsyncSession -): + ): post = await crud_posts.get(db=db, id=post_id) if not post: raise NotFoundException("Post not found") @@ -155,6 +155,10 @@ async def get_post( return post ``` +> **Note:** +> Some CRUD helper functions may evolve to return falsy-but-valid values (e.g. empty objects). +> To future-proof your API, prefer `if post is None:` instead of `if not post:` when checking existence. + ## Validation Errors FastAPI automatically handles Pydantic validation errors, but you can catch and customize them: