Skip to content

fix: validate max_items and offset query params in GET /history#13855

Open
Jefsky wants to merge 2 commits into
Comfy-Org:masterfrom
Jefsky:fix/history-param-validation
Open

fix: validate max_items and offset query params in GET /history#13855
Jefsky wants to merge 2 commits into
Comfy-Org:masterfrom
Jefsky:fix/history-param-validation

Conversation

@Jefsky

@Jefsky Jefsky commented May 12, 2026

Copy link
Copy Markdown

Summary

Passing a non-integer value for max_items or offset query parameters in GET /history caused an unhandled ValueError, resulting in a 500 Internal Server Error instead of a 400 Bad Request.

This brings /history in line with the existing validation pattern used by the adjacent /api/jobs endpoint, which already handles these cases correctly with try/except and returns descriptive 400 errors.

Changes

server.py

  • Wrapped int() conversion for max_items and offset in try/except
  • Returns {"error": "max_items must be an integer", "status": 400} on invalid input
  • Returns {"error": "offset must be an integer", "status": 400} on invalid input

tests/execution/test_execution.py

  • Added test_history_max_items_invalid_returns_400 - parametrized test with multiple invalid string values
  • Added test_history_offset_invalid_returns_400 - parametrized test with multiple invalid string values

Testing

Both new tests use pytest.raises(urllib.error.HTTPError) to verify the 400 status code and error message content.

Fixes #13841

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.
@coderabbitai

coderabbitai Bot commented May 12, 2026

Copy link
Copy Markdown

Review Change Stack
No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: d466d699-079e-4b18-84a5-07bba8a18ad3

📥 Commits

Reviewing files that changed from the base of the PR and between c9589f2 and 87e332f.

📒 Files selected for processing (2)
  • server.py
  • tests/execution/test_execution.py

📝 Walkthrough

Walkthrough

This PR adds input validation to the PromptServer's /history endpoint. The max_items and offset query parameters are now parsed within try/except blocks, returning HTTP 400 responses with descriptive JSON error messages when values cannot be converted to integers. Two corresponding parameterized test cases verify this behavior by submitting non-integer values for each parameter and asserting the expected error responses.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely describes the main change: adding validation for max_items and offset query parameters in the GET /history endpoint.
Description check ✅ Passed The description clearly explains the problem, solution, and changes made, directly relating to the code modifications in the PR.
Linked Issues check ✅ Passed The PR fully addresses issue #13841 by implementing input validation for max_items and offset parameters with try/except blocks and 400 error responses.
Out of Scope Changes check ✅ Passed All changes are directly related to the linked issue objective of validating query parameters in GET /history with no extraneous modifications.

✏️ 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.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant