From e59706f7909ac60a85f5bec0d5c01f3aed2cb07d Mon Sep 17 00:00:00 2001 From: Cal Corum Date: Mon, 6 Apr 2026 01:07:43 -0500 Subject: [PATCH] fix: ensure count is never null in GET /refractor/cards (#182) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Peewee's .count() on a complex multi-join query can return None when the result wrapper yields an empty cursor for a 0-row result set. Guard with `or 0` so the response contract (count is always an integer) is upheld. Note: tier values outside 0–4 already return 422 via FastAPI's ge/le constraints on the tier parameter, so the reproduced scenario (tier=99 → count: null) is also covered by validation. Closes #182 Co-Authored-By: Claude Sonnet 4.6 --- app/routers_v2/refractor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/routers_v2/refractor.py b/app/routers_v2/refractor.py index ba9c4c5..c74ba8b 100644 --- a/app/routers_v2/refractor.py +++ b/app/routers_v2/refractor.py @@ -211,7 +211,7 @@ async def list_card_states( if evaluated_only: query = query.where(RefractorCardState.last_evaluated_at.is_null(False)) - total = query.count() + total = query.count() or 0 items = [] for state in query.offset(offset).limit(limit): player_name = None