Repository navigation
Reject non-integer pagination bounds in iter_reviews - #80
Open
VictortheGreat7 wants to merge 1 commit into
Open
VictortheGreat7 wants to merge 1 commit into
VictortheGreat7 wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
_page_limits(used byiter_reviews, sync and async) only compares its arguments with<=, so it accepts values that are not valid integers. Calling it directly onmain:mainpage_size2.5page_sizeTruemax_pages2.5max_items2.5page_size"10"TypeErrorThrough the iterator,
max_items="10"fails withTypeError: '<=' not supported between instances of 'int' and 'str', while out-of-range numbers raise the documentedValueError.This has a real effect for
max_items. The loop checkscount == max_items, which can never be true for a float, so the documentedpagination-limitbound never fires. With a server that returns two items andmax_items=1.5,iter_reviewsyielded both items and raised nothing, in sync and async mode. Withmax_items=1the same server raisespagination-limit._export_page_limitalready rejects bools and non-integers, so the reviews iterator was inconsistent with it.max_items=1.5 demonstration (throwaway test, not committed)
main:yielded 2 items with max_items=1.5(sync and async)ValueError: Pagination requires page_size 1..100, max_pages 1..1000, max_items 1..100000.before any requestFix
The ranges and the
ValueErrormessage are unchanged. Behaviour change: values that are not integers, such as"10", now raiseValueErrorinstead ofTypeError.Tests
30 new cases in
tests/test_http.py, each run in sync and async mode against the loopback server, asserting that no request reaches it:0and one above the maximum for each argument), which pass before and after and guard against loosening the existing limitsTrue,1.5,"10"for each argument), which fail onmainand pass hereTo reproduce the failures:
Not included
_export_page_limithas the same check inline and could use_in_range; I left it alone to avoid conflicts with the open export PRs, and behaviour would not change.iter_reviewsis a generator, so theValueErroris raised on first iteration, not at call time.iter_export_pagesbehaves the same way and its tests rely on it, so I left it.Checks
python3 scripts/check.pypasses locally: generation check, contracts, ruff, mypy, 249 tests (8 subtests), and sdist and wheel installs. Run on Linux with Python 3.14.4; CI pins 3.13.12.Proofline review
I installed Proofline on my fork and it reviewed this change there: VictortheGreat7#1
The review completed on commit f6f0588 (base 1f389da), before I rebased onto the current main, and reported no findings. From the API: the code assessment ran for about 30 seconds and completed with an empty findings list.
Because it gave me nothing to act on, I conducted a diff review with help:
isinstance(value, int)rejects NumPy integer types, as_export_page_limitdoes.
operator.indexwould accept them while still rejecting floats; I chose consistency.max_pagesfor the export iterator (it already says "an integer from 1 to 1000", consistent with this change).