Skip to content

Commit 112cc6a

Browse files
committed
fix: added query validation
1 parent 3da44fa commit 112cc6a

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,9 +3,10 @@
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
9+
from diracx.logic.pilots.query import MAX_PER_PAGE
910
from diracx.logic.pilots.query import search as search_bl
1011
from diracx.logic.pilots.query import summary as summary_bl
1112

@@ -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
@@ -140,8 +140,8 @@ async def _search(
140140

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

143-
if r.status_code == 400:
144-
# If we have a status_code 400, that means that the query failed
143+
if r.status_code in (400, 422):
144+
# If we have a status_code 400/422, that means that the query failed
145145
raise InvalidQueryError()
146146

147147
return r.json(), r.headers

0 commit comments

Comments
 (0)