Skip to content

Commit 67b145b

Browse files
fstagnialdbr
authored andcommitted
fix: added query validation
1 parent 2e58125 commit 67b145b

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

diracx-routers/src/diracx/routers/pilots/query.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
from http import HTTPStatus
44
from typing import Annotated, Any
55

6-
from fastapi import Body, Depends, Response
6+
from fastapi import Body, Depends, Query, Response
77

88
from diracx.core.models.search import SearchParams, SummaryParams
99
from diracx.db.sql import PilotAgentsDB
10+
from diracx.logic.pilots.query import MAX_PER_PAGE
1011
from diracx.logic.pilots.query import search as search_bl
1112
from diracx.logic.pilots.query import summary as summary_bl
1213

@@ -111,8 +112,8 @@ async def search(
111112
check_permissions: CheckPilotManagementPolicyCallable,
112113
response: Response,
113114
user_info: Annotated[AuthorizedUserInfo, Depends(verify_dirac_access_token)],
114-
page: int = 1,
115-
per_page: int = 100,
115+
page: Annotated[int, Query(ge=1)] = 1,
116+
per_page: Annotated[int, Query(ge=1, le=MAX_PER_PAGE)] = 100,
116117
body: Annotated[
117118
SearchParams | None, Body(openapi_examples=EXAMPLE_SEARCHES) # type: ignore
118119
] = None,

diracx-routers/tests/pilots/test_query.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ async def _search(
133133

134134
r = populated_pilot_client.post("/api/pilots/search", json=body, params=params)
135135

136-
if r.status_code == 400:
137-
# If we have a status_code 400, that means that the query failed
136+
if r.status_code in (400, 422):
137+
# If we have a status_code 400/422, that means that the query failed
138138
raise InvalidQueryError()
139139

140140
return r.json(), r.headers

0 commit comments

Comments
 (0)