Skip to content

Commit 1e91b27

Browse files
committed
small fixes
1 parent 6ab5331 commit 1e91b27

File tree

5 files changed

+14
-27
lines changed

5 files changed

+14
-27
lines changed

Taskfile.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,10 @@ tasks:
2929
cmds:
3030
- docker compose build application
3131

32-
lock:
33-
desc: lock with update
34-
cmds:
35-
- uv lock --upgrade
36-
3732
install:
3833
desc: "install local dependencies"
3934
cmds:
35+
- uv lock --upgrade
4036
- uv sync --all-extras --no-install-project --frozen
4137

4238
lint:

app/application.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def __init__(self) -> None:
2323
include_routers(self.app)
2424
self.app.add_exception_handler(
2525
ForeignKeyError,
26-
exceptions.database_validation_exception_handler, # type: ignore[arg-type]
26+
exceptions.foreign_key_error_handler, # type: ignore[arg-type]
2727
)
2828

2929
@contextlib.asynccontextmanager

app/exceptions.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
11
from advanced_alchemy.exceptions import ForeignKeyError
2-
from fastapi.exception_handlers import request_validation_exception_handler
3-
from fastapi.exceptions import RequestValidationError
42
from fastapi.responses import JSONResponse
3+
from starlette import status
54
from starlette.requests import Request
65

76

8-
async def database_validation_exception_handler(request: Request, exc: ForeignKeyError) -> JSONResponse:
9-
validation_error = RequestValidationError(
10-
[
11-
{
12-
"loc": ["__root__"],
13-
"msg": exc.detail,
14-
"input": {},
15-
"ctx": {"error": exc.detail},
16-
},
17-
],
18-
body=exc.detail,
7+
async def foreign_key_error_handler(_: Request, exc: ForeignKeyError) -> JSONResponse:
8+
return JSONResponse(
9+
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
10+
content={"detail": exc.detail},
1911
)
20-
return await request_validation_exception_handler(request, validation_error)

tests/test_cards.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ async def test_create_cards(
9696
)
9797
data = response.json()
9898
assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
99-
assert data["detail"][0]["msg"] == "A foreign key is missing or invalid"
99+
assert data["detail"] == "A foreign key is missing or invalid"
100100

101101

102102
@inject

uv.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)