Skip to content

Refactor query validation bad request errors (#936)#1179

Open
2lll5 wants to merge 1 commit into
ramimbo:mainfrom
2lll5:cleanup/query-validation-bad-request-helper
Open

Refactor query validation bad request errors (#936)#1179
2lll5 wants to merge 1 commit into
ramimbo:mainfrom
2lll5:cleanup/query-validation-bad-request-helper

Conversation

@2lll5

@2lll5 2lll5 commented Jun 29, 2026

Copy link
Copy Markdown

Summary

  • Adds a small shared helper for query-validation 400 responses
  • Replaces repeated HTTPException(status_code=400, detail=...) blocks in app/query_validation.py
  • Preserves existing validation behavior and error details

Bounty: #936

Verification

  • python3 -m pytest tests/test_query_validation.py
  • python3 -m ruff check app/query_validation.py tests/test_query_validation.py
  • python3 -m ruff format --check app/query_validation.py tests/test_query_validation.py

Summary by CodeRabbit

  • Refactor
    • Streamlined query parameter validation to handle bad requests more consistently.
    • User-facing 400 responses and error messages remain unchanged, while invalid query input is now rejected through a single shared path.

@coderabbitai

coderabbitai Bot commented Jun 29, 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: ASSERTIVE

Plan: Pro Plus

Run ID: f906588d-af04-4db2-b273-9090b1613781

📥 Commits

Reviewing files that changed from the base of the PR and between 3bc87d2 and 2c5ba9b.

📒 Files selected for processing (1)
  • app/query_validation.py

📝 Walkthrough

Walkthrough

Adds a private helper _raise_bad_query_param(detail) in app/query_validation.py and replaces all inline HTTPException(status_code=400, detail=...) constructions across control-character, integer canonicality, boolean alias, repeated-parameter, and unsupported-parameter validators with calls to it. No public API or message strings change.

Query Validation Refactor

Layer / File(s) Summary
Helper and validator updates
app/query_validation.py
Introduces _raise_bad_query_param(detail) (lines 15–25) and updates all five validation sites — control chars, non-canonical integers, boolean aliases, repeated scalars, unsupported params — to call the helper instead of constructing HTTPException inline.

Possibly related PRs

  • ramimbo/mergework#886: Also refactors app/query_validation.py validators to centralize rejection logic at the same guard-function level.
🚥 Pre-merge checks | ✅ 4 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers summary and verification, but it omits the required Evidence, Test Evidence checklist, and MRWK sections from the template. Add the missing template sections with the addressed issue context, affected surfaces, expected size/out-of-scope notes, the test checklist, and the MRWK reference.
Bounty Pr Focus ⚠️ Warning The commit is a repo-wide initial add of many unrelated files, not a focused query_validation-only bounty fix. Restrict the PR to the stated query-validation surfaces (and any direct tests), and include actual test output if verification is claimed.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is short and concrete, and it names the changed surface in app/query_validation.py.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Mergework Public Artifact Hygiene ✅ Passed PASS: The PR description has no price/investment/cash-out/private-security claims, and the only changed file is app/query_validation.py.

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.

@qingfeng312 qingfeng312 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

The change is a small, behavior-preserving refactor: the repeated HTTPException(status_code=400, detail=...) branches are centralized behind _raise_bad_query_param, while each query-validation path keeps the same status code and detail strings. The PR is limited to app/query_validation.py, and the full quality workflow is green.

Evidence: GitHub Actions run 28345759957, job 83968629778, successful.

@yanyishuai yanyishuai left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review packet (Bounty #933)

  • Reviewed PR: #1179
  • Head commit: 2c5ba9b5b90514010c8ae30b583738b0769bb53f
  • Scope inspected: query-parameter validation / bad-request error shaping for public API routes
  • Verdict: Focused refactor with clear error envelopes for invalid query input. CI quality gate passes on current head. The change improves agent-facing debuggability without altering successful-path behavior.
  • Notes: Overlaps thematically with other validation-hardening PRs in the queue; maintainers should ensure merge order avoids duplicate error-message drift. No treasury/payout surface touched.

Bounty #933

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.

3 participants