[client] _paginate: harden loop termination (missing totalPages) and duplicate page= param #181

Closed
opened 2026-10-27 11:31:55 +00:00 by mat · 0 comments
Owner

_paginate (_core.py:113-123) has two weaknesses:

  1. Infinite loop on a misbehaving server: termination relies on an empty content page or the totalPages counter. If the server omits totalPages and keeps returning non-empty pages, the loop never ends.
  2. Duplicate page= param: the separator logic ("&" if "?" in path else "?", _core.py:114) blindly appends page={n}, so a path that already carries page= yields two conflicting page params.

Fix:

  • guard against a page= already present in the path (strip or fail loudly — never silently send both);
  • add a documented safety bound for the missing-totalPages case (e.g. a max page count) that raises ComwattAPIError instead of hanging.

Done when: tests cover (a) a page= already in the path, and (b) a server omitting totalPages that keeps returning items — terminating via the bound instead of hanging.

`_paginate` (`_core.py:113-123`) has two weaknesses: 1. **Infinite loop on a misbehaving server:** termination relies on an empty `content` page or the `totalPages` counter. If the server omits `totalPages` and keeps returning non-empty pages, the loop never ends. 2. **Duplicate `page=` param:** the separator logic (`"&" if "?" in path else "?"`, `_core.py:114`) blindly appends `page={n}`, so a path that already carries `page=` yields two conflicting `page` params. **Fix:** - guard against a `page=` already present in the path (strip or fail loudly — never silently send both); - add a documented safety bound for the missing-`totalPages` case (e.g. a max page count) that raises `ComwattAPIError` instead of hanging. **Done when:** tests cover (a) a `page=` already in the path, and (b) a server omitting `totalPages` that keeps returning items — terminating via the bound instead of hanging.
mat closed this issue 2026-10-27 14:36:36 +00:00
Sign in to join this conversation.
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#181
No description provided.