fix: ensure count is never null in GET /refractor/cards (#182)

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 <noreply@anthropic.com>
This commit is contained in:
Cal Corum 2026-04-06 01:07:43 -05:00
parent cc65dc5395
commit e59706f790

View File

@ -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