bug: /refractor status page overflow shows "no data" instead of clamping to last page #141

Closed
opened 2026-04-07 15:20:32 +00:00 by cal · 1 comment
Owner

Description

When a user passes a page number beyond the total pages (e.g. /refractor status page:999), the bot returns "No refractor data found for your team." instead of clamping to the last valid page.

Root Cause

In cogs/refractor.py, the status command sends limit and offset directly to the API (line 338-339). When page=999, the offset becomes 9980, the API returns {"count": 13, "items": []}, and the cog falls through to the "no data" message at line 380 without checking that count > 0.

The paginate() helper function (line 194) handles clamping correctly, but it's not used here — pagination is done server-side.

Expected Behavior

/refractor status page:999 should clamp to the last page and display those cards (same as /refractor status page:0 correctly clamps to page 1).

Suggested Fix

After the API call, when items is empty but total_count > 0, recalculate the page to ceil(total_count / PAGE_SIZE) and re-fetch with the corrected offset. Or pre-clamp on the first request by fetching count first.

Steps to Reproduce

  1. Have a team with refractor data (e.g. team 31 on dev with 13 cards)
  2. Run /refractor status page:999
  3. Observe: "No refractor data found for your team."
  4. Expected: Shows last page of cards (Page 2/2)

Test Reference

REF-22 in tests/refractor-integration-test-plan.md

## Description When a user passes a page number beyond the total pages (e.g. `/refractor status page:999`), the bot returns "No refractor data found for your team." instead of clamping to the last valid page. ## Root Cause In `cogs/refractor.py`, the status command sends `limit` and `offset` directly to the API (line 338-339). When page=999, the offset becomes 9980, the API returns `{"count": 13, "items": []}`, and the cog falls through to the "no data" message at line 380 without checking that `count > 0`. The `paginate()` helper function (line 194) handles clamping correctly, but it's not used here — pagination is done server-side. ## Expected Behavior `/refractor status page:999` should clamp to the last page and display those cards (same as `/refractor status page:0` correctly clamps to page 1). ## Suggested Fix After the API call, when `items` is empty but `total_count > 0`, recalculate the page to `ceil(total_count / PAGE_SIZE)` and re-fetch with the corrected offset. Or pre-clamp on the first request by fetching count first. ## Steps to Reproduce 1. Have a team with refractor data (e.g. team 31 on dev with 13 cards) 2. Run `/refractor status page:999` 3. Observe: "No refractor data found for your team." 4. Expected: Shows last page of cards (Page 2/2) ## Test Reference REF-22 in `tests/refractor-integration-test-plan.md`
Claude added the
ai-working
label 2026-04-07 15:30:31 +00:00
Claude removed the
ai-working
label 2026-04-07 15:32:21 +00:00
Collaborator

PR #142 opened: #142

Fix adds a re-fetch guard after the initial API call: when items is empty but total_count > 0, the page is clamped to the last valid page and a second request is made with the corrected offset. Ruff passed clean.

PR #142 opened: https://git.manticorum.com/cal/paper-dynasty-discord/pulls/142 Fix adds a re-fetch guard after the initial API call: when `items` is empty but `total_count > 0`, the page is clamped to the last valid page and a second request is made with the corrected offset. Ruff passed clean.
Claude added the
ai-pr-opened
label 2026-04-07 15:32:26 +00:00
cal closed this issue 2026-04-07 15:52:08 +00:00
Sign in to join this conversation.
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: cal/paper-dynasty-discord#141
No description provided.