Repository navigation
fix(api): return 422 for out-of-range pagination query values - #15223
Lesereingrape wants to merge 1 commit into
Conversation
custom_params declared page/size as unbounded Query(None) and then handed them to fastapi_pagination.Params, whose own constraints validate size as ge=1, le=100. An out-of-range value therefore raised ValidationError inside dependency resolution: the route never ran and the app-wide Exception handler answered 500 with the raw validation text, while falsy values (page=0, size=0) were silently rewritten to defaults. Declare the same bounds on the query parameters so FastAPI rejects them as 422, matching what the sibling routes built on Depends(Params) already do.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: langflow-ai/langflow/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. WalkthroughThe shared ChangesPagination validation
Priority: ➖ Normal Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix · Severity of issue fixed: Medium Suggested reviewers: 🚥 Pre-merge checks | ✅ 8 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (8 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
Changes
custom_paramsdeclaredpage/sizeas unboundedQuery(None)and then passed them tofastapi_pagination.Params, which validatessizeasge=1, le=100itself. So an out-of-range value raisedValidationErrorduring dependency resolution — before the handler, which puts it past the route's owntry/exceptand into the app-wideExceptionhandler inmain.py, answering 500 with the internal validation text echoed to the client.This declares the same bounds on the query parameters so FastAPI rejects them as 422, matching the sibling routes that already depend on
Paramsdirectly.Fixes #15222
Affected routes:
/api/v1/monitor/transactions,/api/v1/projects/{project_id},/api/v1/folders/{folder_id}.Nothing that works today changes:
Nonefor both parameters still means "unpaginated",size=100is still the ceiling, and?page=3still defaultssizetoMAX_PAGE_SIZE.page=0/size=0now return 422 instead of being silently rewritten to the defaults.How was this tested
src/backend/tests/unit/api/test_api_utils.py— a minimalFastAPI()app whose only dependency iscustom_params, so no database, no network, no service setup:MAX_PARAMS_PAGE_SIZE/MIN_PAGE_SIZEagainst the boundsParamsitself carries, because the bounds are now declared in two placesMeasured locally on
main@5621dcfd(Python 3.12,uv, Windows):make format_backend/make unit_testswere not run —makeis not available on this machine, so theuv runequivalents above are what actually executed. Importing and building themonitor,projectsandfoldersrouters was also checked, because FastAPI validates aQuerybound at route-build time: all three still build (this is what caught an earlier version of the fix that put theNonedefault insideAnnotated, which FastAPI rejects).What else to consider
str(exc)— out of scope here.MAX_PAGE_SIZE = 50is still only a default, not a bound, so the accepted ceiling stays 100 (whatParamsallows). Tightening it to 50 would turn currently-workingsize=51..100requests into 422s, so I deliberately left it alone.MIN_PAGE_SIZEis reused as thegefor both parameters; it already equals thege=1thatParamsputs onpage.Attribution: this change was prepared by an AI coding agent working from the account holder's instruction, and has not been reviewed by a human before opening. The RED/GREEN numbers above are measured output, not estimates.
Summary by CodeRabbit