getredash/redash · warning
Page is out of range.
Error message
Page is out of range.
What it means
Raised by paginate() in redash/handlers/base.py when the requested page starts past the end of the result set, i.e. (page-1)*page_size + 1 exceeds the total count while count > 0. It prevents Flask-SQLAlchemy's paginate from returning an empty items list for a nonsensical page.
Source
Thrown at redash/handlers/base.py:87
def get_object_or_404(fn, *args, **kwargs):
try:
rv = fn(*args, **kwargs)
if rv is None:
abort(404)
except NoResultFound:
abort(404)
return rv
def paginate(query_set, page, page_size, serializer, **kwargs):
count = query_set.count()
if page < 1:
abort(400, message="Page must be positive integer.")
if (page - 1) * page_size + 1 > count > 0:
abort(400, message="Page is out of range.")
if page_size > 250 or page_size < 1:
abort(400, message="Page size is out of range (1-250).")
results = query_set.paginate(page, page_size)
# support for old function based serializers
if isclass(serializer):
items = serializer(results.items, **kwargs).serialize()
else:
items = [serializer(result) for result in results.items]
return {"count": count, "page": page, "page_size": page_size, "results": items}
def org_scoped_rule(rule):
if settings.MULTI_ORG:
return "/<org_slug>{}".format(rule)View on GitHub (pinned to ca79fe988d)
Solutions
- Re-query page 1 or clamp page to ceil(count/page_size) when you get this 400.
- Refresh total count before requesting later pages; re-read the 'count' field from the response of the previous page.
- Pass a smaller page number or larger page_size within the 1-250 limit.
Example fix
# before
page = stale_page # e.g. 3 but only 1 page exists
resp = client.get(f'/api/queries?page={page}&page_size=25')
# after
resp = client.get(f'/api/queries?page={min(stale_page, max(1, count // 25 + 1))}&page_size=25') Defensive patterns
Strategy: validation
Validate before calling
count = resp_json['count'] max_page = max(1, -(-count // page_size)) page = min(page, max_page)
Try / catch
try:
resp = client.get(url)
except HTTPError as e:
if e.response.status_code == 400 and 'out of range' in e.response.text:
resp = client.get(url_with_page_1)
else:
raise Prevention
- Always read 'count' from the API response and compute the last page locally.
- After deletions or filter changes, restart pagination from page 1.
When it happens
Trigger: Requesting a page beyond the last one, e.g. 30 results with page_size=25 and ?page=3 (starts at item 51 > 30). Typically after data is deleted or filters shrink the result set while a client keeps a stale page parameter.
Common situations: Deleting many rows then refreshing a paginated view that still points to the old page; concurrent filtering that reduces counts; hardcoding a page number that only existed with older data.
Related errors
- Page must be positive integer.
- Page size is out of range (1-250).
- Unknown 'pagination.type' {}
- 'pagination.path' should be a string
- 'pagination.fields' should be a list of 2 field names
AI-assisted analysis of getredash/redash@ca79fe988d (2026-08-28).
Data as JSON: /api/errors/93792bef1b46b75f.
Report an issue: GitHub.