Fix sync _get_pages_iterator silently dropping the last page#326
Open
jgarber-cisco wants to merge 1 commit intomeraki:mainfrom
Open
Fix sync _get_pages_iterator silently dropping the last page#326jgarber-cisco wants to merge 1 commit intomeraki:mainfrom
jgarber-cisco wants to merge 1 commit intomeraki:mainfrom
Conversation
The iterator broke out of the while loop when no next/prev link was present, skipping the yield of the final page's items. Replace the break with total_pages = 1 so the last page is yielded before the loop exits, matching the async iterator's existing behavior. Made-with: Cursor
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.
Bug
The synchronous
_get_pages_iteratorinRestSessionsilently drops the last page of paginated results. When iterating through all pages withtotal_pages="all"(or-1), every page except the final one is yielded correctly. The final page is fetched and parsed, but its items are never yielded to the caller.Root cause
The
whileloop in_get_pages_iteratorchecks for anext(orprev) link in the response headers. When the last page has no such link, theelsebranch executedbreak, which exited the loop before reaching theyieldblock below it:Impact
Any caller using the iterator pagination mode (
use_iterator_for_get_pages=True) and paginating through all pages would silently receive fewer results than expected — missing the entire last page. For example, 100 items at 10 per page would yield only 90 items.The legacy pagination mode (
_get_pages_legacy) is not affected — it uses a different loop structure that correctly accumulates all pages.Fix
Replace
breakwithtotal_pages = 1. This allows the loop body to continue — closing the response, extracting items, and yielding them — thentotal_pagesdecrements to0, and thewhile total_pages != 0condition exits the loop naturally. The subsequentif total_pages != 0guard prevents any further request from being made, so the stalenextlinkvariable is never used.This is a one-line change that makes the sync iterator match the async iterator (
AsyncRestSession._get_pages_iterator), which already handles this correctly with the sametotal_pages = 1pattern at aio/rest_session.py line 375.Test plan
total_pages = 1and is unaffected.break.tests/test_dashboard_api_python_library.pybecause it requires production API keys.Author: Jason Garber (@jgarber-cisco)
Made with Cursor