Skip to content

Commit cb72d4e

Browse files
authored
Merge pull request #214 from carlosplanchon/main
Adding note on exceptions.md about falsy values possibly coming from FastCRUD in the future.
2 parents 21fa78f + 4e966ca commit cb72d4e

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,6 @@ cython_debug/
132132

133133
.ruff_cache
134134

135-
.idea
135+
.idea
136+
137+
.vscode/

docs/user-guide/api/exceptions.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ from app.core.exceptions.http_exceptions import ForbiddenException
6363
async def delete_user(
6464
user_id: int,
6565
current_user: Annotated[dict, Depends(get_current_user)]
66-
):
66+
):
6767
if current_user["id"] != user_id and not current_user["is_superuser"]:
6868
raise ForbiddenException("You can only delete your own account")
6969

@@ -121,7 +121,7 @@ async def update_user(
121121
user_id: int,
122122
user_data: UserUpdate,
123123
db: AsyncSession
124-
):
124+
):
125125
# Check if user exists
126126
if not await crud_users.exists(db=db, id=user_id):
127127
raise NotFoundException("User not found")
@@ -143,7 +143,7 @@ async def get_post(
143143
post_id: int,
144144
current_user: Annotated[dict, Depends(get_current_user)],
145145
db: AsyncSession
146-
):
146+
):
147147
post = await crud_posts.get(db=db, id=post_id)
148148
if not post:
149149
raise NotFoundException("Post not found")
@@ -155,6 +155,10 @@ async def get_post(
155155
return post
156156
```
157157

158+
> **Note:**
159+
> Some CRUD helper functions may evolve to return falsy-but-valid values (e.g. empty objects).
160+
> To future-proof your API, prefer `if post is None:` instead of `if not post:` when checking existence.
161+
158162
## Validation Errors
159163

160164
FastAPI automatically handles Pydantic validation errors, but you can catch and customize them:

0 commit comments

Comments
 (0)