Skip to content

fix(api): return 422 for missing QueryParams fields - #7630

Open
axelray-dev wants to merge 3 commits into
openbq-org:developfrom
axelray-dev:hotfix/queryparams-missing-422
Open

axelray-dev wants to merge 3 commits into
openbq-org:developfrom
axelray-dev:hotfix/queryparams-missing-422

Conversation

@axelray-dev

@axelray-dev axelray-dev commented Aug 4, 2026 •

Copy link
Copy Markdown

Summary

Missing required fields on a QueryParams model now return HTTP 422 with query-scoped error locations. Response validation remains 422, while non-query validation errors keep the existing 500 fallback.

Fixes #7629.

Tests

uv run --project openbb_platform/core --no-dev --with pytest --with pytest-asyncio pytest -q openbb_platform/core/tests/api/test_exception_handlers.py (14 passed)

@CLAassistant

CLAassistant commented Aug 4, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@axelray-dev
axelray-dev marked this pull request as ready for review August 4, 2026 17:36

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

Sensibly dropping the all_in_query condition since every QueryParams validation should indeed surface as a query-param error. The one case to double check: a QueryParams-backed model can also be used to bind a request body in some routes, and for those the detail will now wrongly claim it sits in query params — confirm the involved routes all read from the query string, otherwise keep a guard that checks whether the request carried a body.

@axelray-dev

Copy link
Copy Markdown
Author

Addressed the body-binding edge case from your review.

The handler now rewrites a QueryParams validation location to query only when the request body is empty. A non-empty-body validation error follows the normal error path, so a body-bound model is not reported as a query parameter error.

Added a regression test for a QueryParams model with a request body. Validation on the updated branch:

  • pytest openbb_platform/core/tests/api/test_exception_handlers.py -q -- 4 passed
  • Ruff check and format check -- passed
  • git diff --check -- passed

Please re-review the updated thread.

@axelray-dev

Copy link
Copy Markdown
Author

Verified the current head includes the body-binding guard requested in review: QueryParams errors are rewritten to query-scoped 422 details only when the request body is empty; body-bound validation follows the normal 500 path. VPS validation: 4 passed for openbb_platform/core/tests/api/test_exception_handlers.py. No additional code change was needed.

@axelray-dev

Copy link
Copy Markdown
Author

I verified the concern against the current branch. The handler now keeps QueryParams relabeling only for requests with no body, and the regression suite covers both a missing query field and a QueryParams-shaped validation error from a body-bound request. On the VPS, openbb_platform/core/tests/api/test_exception_handlers.py passes: 4 passed. I did not find a further code change required for the reviewer’s stated case.

@axelray-dev

Copy link
Copy Markdown
Author

Confirmed the review concern is handled in the current head: the QueryParams relabeling is now guarded by
ot await request.body(), and the focused regression test covers a QueryParams validation error on a body-bearing request and keeps it on the 500 path. The missing-query case remains 422 with query-scoped details.

@axelray-dev
axelray-dev force-pushed the hotfix/queryparams-missing-422 branch from 18dcfe6 to 6bf62b5 Compare October 11, 2026 18:57
@axelray-dev
axelray-dev force-pushed the hotfix/queryparams-missing-422 branch from ea8c247 to e07c28b Compare October 14, 2026 06:30

This branch has not been deployed

No deployments
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.

[Bug] Fetcher-level pydantic ValidationError returns 500 "Unexpected Error" instead of 422 (e.g. bls_search without category)

3 participants