fix: validate max_items and offset query params in GET /history#13855
fix: validate max_items and offset query params in GET /history#13855Jefsky wants to merge 2 commits into
Conversation
Passing a non-integer value for max_items or offset caused an unhandled ValueError, resulting in a 500 instead of a 400. This brings /history in line with the existing validation pattern used by /api/jobs. Tests added for both max_items and offset with multiple invalid string values.
|
ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThis PR adds input validation to the 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
Passing a non-integer value for
max_itemsoroffsetquery parameters inGET /historycaused an unhandledValueError, resulting in a 500 Internal Server Error instead of a 400 Bad Request.This brings
/historyin line with the existing validation pattern used by the adjacent/api/jobsendpoint, which already handles these cases correctly with try/except and returns descriptive 400 errors.Changes
server.py
int()conversion formax_itemsandoffsetin try/except{"error": "max_items must be an integer", "status": 400}on invalid input{"error": "offset must be an integer", "status": 400}on invalid inputtests/execution/test_execution.py
test_history_max_items_invalid_returns_400- parametrized test with multiple invalid string valuestest_history_offset_invalid_returns_400- parametrized test with multiple invalid string valuesTesting
Both new tests use
pytest.raises(urllib.error.HTTPError)to verify the 400 status code and error message content.Fixes #13841