Repository navigation
Reject bool values in pagination limits - #133
mohityadav8 wants to merge 1 commit into
Conversation
_page_limits accepted True/False as page_size, max_pages, or max_items since bool is an int subclass in Python, silently treating them as 1/0 instead of raising. _export_page_limit already guards against this; bring _page_limits in line with it. Verified: _page_limits(True, 10, 100) raised nothing before the fix, raises ValueError after. Same 3 pre-existing test failures (openapi-python-client metadata, Windows socket timing flakes) reproduce identically on main, confirming this change introduces no regressions.
There was a problem hiding this comment.
Thanks for this — _export_page_limit is a good precedent to follow, and the bool fix reads clearly.
I checked the behaviour by extracting _page_limits from main and from your head: on main, _page_limits(True, 10, 100) returns without error; on your head it raises ValueError: Pagination requires page_size 1..100, .... So the change does what it says.
One optional extra, if you have time: there does not seem to be a test that calls _page_limits yet (the only references I found were the two call sites at client.py:519,914). A tiny parametrized test would keep the bool case from coming back. I sketched one in this comment — please use any part of it that is useful, or ignore it if you would rather handle coverage elsewhere.
I verified by extracting the function rather than by running pytest, since this checkout has no Python deps installed. No repo of yours was touched. Nice small fix, and thanks for noting the pre-existing failures — that was helpful context.
|
|
||
| def _page_limits(page_size: int, max_pages: int, max_items: int) -> None: | ||
| if not 1 <= page_size <= 100 or not 1 <= max_pages <= 1_000 or not 1 <= max_items <= 100_000: | ||
| if ( |
There was a problem hiding this comment.
The logic looks good to me. If you would like a companion test, a small parametrized one in tests/ would keep the bool case from coming back — there is no coverage of _page_limits in the suite today. Totally optional, and happy with whatever you prefer.
_page_limits accepted True/False as page_size, max_pages, or max_items since bool is an int subclass in Python, silently treating them as 1/0 instead of raising. _export_page_limit already guards against this; bring _page_limits in line with it. Verified: _page_limits(True, 10, 100) raised nothing before the fix, raises ValueError after. Same 3 pre-existing test failures (openapi-python-client metadata, Windows socket timing flakes) reproduce identically on main, confirming this change introduces no regressions.