Repository navigation
fix(pagination): clamp out-of-range page and size #1476 - #1477
Open
borealisalastor-byte wants to merge 1 commit into
Open
borealisalastor-byte wants to merge 1 commit into
borealisalastor-byte wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
pageNum/pageSize路径参数直接进入PaginationParams,Paginator对两者都没有边界检查:pageSize=0:(total + size - 1) // size抛ZeroDivisionError,列表接口返回 500;pageNum=0:offset = (page - 1) * size为-size,PostgreSQL 报OFFSET must not be negative,同样是 500;pageSize无上限:pageSize=100000会让一次列表请求构造超大查询。/system/user/pager/{pageNum}/{pageSize}、system/workspace成员列表、system_variable等接口都直接构造PaginationParams,因此都会命中。改动
新增
normalize_page_args,在Paginator.paginate与Paginator.get_paginated_response入口归一化:page < 1 → 1、size < 1 → 20、size > 500 → 500;归一化后的值用于 offset、total_pages和响应里的page/size。合法入参的行为不变。验证(
cd backend后执行,无需数据库)pytest -q tests/test_pagination_arguments.py→ 5 passed(修复前该场景直接ZeroDivisionError)size=0由抛异常变为返回第 1 页、size=20、total_pages=3;page=0的响应page由 0 修正为 1,offset 不再为负;size=100000收敛为 500pytest -q tests --continue-on-collection-errors→ 373 passed;仅test_model_discovery.py::test_real_route_permission_and_safe_error因本机缺少sqlbot_xpack失败,与改动无关Fixes #1476