Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/a2a/server/request_handlers/rest_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
SubscribeToTaskRequest,
)
from a2a.utils import proto_utils
from a2a.utils.errors import ServerError, TaskNotFoundError
from a2a.utils.errors import InvalidParamsError, ServerError, TaskNotFoundError
from a2a.utils.helpers import validate
from a2a.utils.telemetry import SpanKind, trace_class

Expand Down Expand Up @@ -249,7 +249,16 @@ async def on_get_task(
"""
task_id = request.path_params['id']
history_length_str = request.query_params.get('historyLength')
history_length = int(history_length_str) if history_length_str else None
try:
history_length = (
int(history_length_str) if history_length_str else None
)
except ValueError:
raise ServerError(
error=InvalidParamsError(
message='historyLength must be a valid integer'
)
) from None
params = GetTaskRequest(id=task_id, history_length=history_length)
task = await self.request_handler.on_get_task(params, context)
if task:
Expand Down
12 changes: 12 additions & 0 deletions tests/server/apps/rest/test_rest_fastapi_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,5 +396,17 @@ async def test_send_message_rejected_task(
assert expected_response == actual_response


@pytest.mark.anyio
async def test_get_task_invalid_history_length_returns_422(
client: AsyncClient,
) -> None:
"""Non-numeric historyLength query param returns 422 InvalidParamsError."""
response = await client.get('/v1/tasks/some-task-id?historyLength=abc')
assert response.status_code == 422
data = response.json()
assert 'message' in data
assert 'historylength' in data['message'].lower()


if __name__ == '__main__':
pytest.main([__file__])
Loading