Repository navigation
fix(paginator): leave pagination unchanged when the page size is invalid - #1091
Merged
andrinoff merged 1 commit intoNov 18, 2026
Merged
Conversation
Return the existing page count when PerPage is zero or negative, matching the no-op behavior for nonpositive item counts. Add separate positive, negative, and regression tests to cover valid calculations, preserved state, and the zero-value divide-by-zero panic.
andrinoff
approved these changes
Nov 18, 2026
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.
Return the existing page count when PerPage is zero or negative, matching the no-op behavior for nonpositive item counts.
Add separate positive, negative, and regression tests to cover valid calculations, preserved state, and the zero-value divide-by-zero panic.
CONTRIBUTING.md.fix(paginator): handle an unset or invalid page size
SetTotalPagesdivides byPerPagewithout checking whether it is positive. Calling it with a positive item count on a zero-value paginator, or afterNew(WithPerPage(0)), therefore panics. A negative page size can also produce an invalid page count.Return the existing
TotalPageswithout changing the model whenPerPageis below one. This follows the method's existing no-op behavior for an item count below one. Positive page sizes retain the current calculation.The patch includes three separate tests:
TotalPages,PageorPerPage.The regression panics for a zero page size on unpatched main; the negative-size case produces a negative page count. Both pass with the fix. The positive and negative controls pass on main and were also shown to fail under their corresponding deliberate breaks.
Open PR #1078 changes the same method for a different input: a valid page size with a shrinking item count. It clamps
Pageto the new last page after calculatingTotalPages, but still divides byPerPagebefore reaching that clamp. This guard prevents the invalid-page-size failure independently; it does not replace #1078 or fix its out-of-range-current-page case. The two changes are complementary.The other paginator-related reports found in the issue search concern separate behavior: #810 and #882 address dot-rendering performance; #405, #406 and #503 concern list layout. This patch does not claim to resolve those reports.
The guard was also tested with #1078's clamp and its regression tests in a separate proof checkout; both sets of tests pass together. This submission contains only the invalid-page-size guard, its documentation and its own tests.
Validation on main
1deada954e6e, Go 1.26.10:-count=4 -cpu=1,4; paginator tests also pass 20 race repetitions.Cross-target binaries were compiled rather than executed. These are local results; remote CI remains to be confirmed.
disclosure: i use ai. i found this bug while working on my own harness with claude. i used claude.. pardon me, i asked claude to root cause, then we worked on the pr you see in front of you, i had codex review it, and kimi said that my skin is looking vibrant today.