From cb17b99220235d47a3d666d9f64cb8ea166d9dc3 Mon Sep 17 00:00:00 2001 From: Cal Corum Date: Tue, 7 Apr 2026 10:31:55 -0500 Subject: [PATCH] fix: clamp page overflow to last page in /refractor status (#141) When page exceeds total pages, API returns empty items but non-zero count. Now detects this case and re-fetches the last valid page. Closes #141 Co-Authored-By: Claude Sonnet 4.6 --- cogs/refractor.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cogs/refractor.py b/cogs/refractor.py index 9a90555..11205d9 100644 --- a/cogs/refractor.py +++ b/cogs/refractor.py @@ -370,6 +370,18 @@ class Refractor(commands.Cog): total_count = ( data.get("count", len(items)) if isinstance(data, dict) else len(items) ) + + # If the requested page is beyond the last page, clamp and re-fetch. + if not items and total_count > 0: + total_pages = max(1, (total_count + PAGE_SIZE - 1) // PAGE_SIZE) + page = total_pages + clamped_params = [(k, v) for k, v in params if k != "offset"] + clamped_params.append(("offset", (page - 1) * PAGE_SIZE)) + data = await db_get("refractor/cards", params=clamped_params) + if isinstance(data, dict): + items = data.get("items", []) + total_count = data.get("count", total_count) + logger.debug( "Refractor status for team %s: %d items returned, %d total (page %d)", team["id"], -- 2.25.1