🐛 fix: harden _paginate (page cap, duplicate page= guard) #199

Merged
mat merged 1 commit from fix/paginate-hardening into main 2026-10-27 14:36:36 +00:00
Owner

Summary

_paginate gets two guards (#181):

entry:   path with its own "page" query param ──► ValueError (fail loudly, never send two)
loop:    page >= _MAX_PAGINATION_PAGES (1000)  ──► ComwattAPIError instead of hanging forever
pinned:  termination on empty page without totalPages (existing behavior, now under test)

The page guard parses the query (parse_qs(urlsplit(path).query)), so ?somepage=1 does not trip it.

Evidence

  • Before: a server omitting totalPages and never returning an empty page looped forever (_core.py:113-123); a path already carrying page= was sent with two conflicting values.
    After: TDD — the guard test written and confirmed red first (ConnectionError instead of ValueError); the cap test run only post-fix (its red state is a hang by construction). pytest -q → 246 passed (+4), mypy → clean.

Merge Danger

Door: two-way

Blast Radius: low — normal pagination paths (totalPages present, or empty-page termination) behave identically; the cap only fires on a misbehaving server.

Closes #181.

## Summary `_paginate` gets two guards (#181): ```text entry: path with its own "page" query param ──► ValueError (fail loudly, never send two) loop: page >= _MAX_PAGINATION_PAGES (1000) ──► ComwattAPIError instead of hanging forever pinned: termination on empty page without totalPages (existing behavior, now under test) ``` The `page` guard parses the query (`parse_qs(urlsplit(path).query)`), so `?somepage=1` does not trip it. ## Evidence - **Before:** a server omitting `totalPages` and never returning an empty page looped forever (`_core.py:113-123`); a path already carrying `page=` was sent with two conflicting values. **After:** TDD — the guard test written and confirmed red first (ConnectionError instead of `ValueError`); the cap test run only post-fix (its red state is a hang by construction). `pytest -q` → 246 passed (+4), `mypy` → clean. ## Merge Danger **Door:** two-way **Blast Radius:** low — normal pagination paths (`totalPages` present, or empty-page termination) behave identically; the cap only fires on a misbehaving server. Closes #181.
🐛 fix: harden _paginate (page cap, duplicate page= guard)
All checks were successful
Tests / forgejo-pytest (push) Successful in 47s
Tests / forgejo-pytest (pull_request) Successful in 45s
3ac68383f1
mat changed title from WIP: 🐛 fix: harden _paginate (page cap, duplicate page= guard) to 🐛 fix: harden _paginate (page cap, duplicate page= guard) 2026-10-27 14:36:34 +00:00
mat merged commit 6074d861f0 into main 2026-10-27 14:36:36 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
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
mat/python-comwatt-client!199
No description provided.