Skip to content

fix: use the new cursor and page size when fetching the next page - #404

Open
Alex Castillo González (pcbeingused33) wants to merge 3 commits into
EasyPost:masterfrom
pcbeingused33:fix/next-page-cursor
Open

Alex Castillo González (pcbeingused33) wants to merge 3 commits into
EasyPost:masterfrom
pcbeingused33:fix/next-page-cursor

Conversation

@pcbeingused33

@pcbeingused33 Alex Castillo González (pcbeingused33) commented Nov 27, 2026 •

Copy link
Copy Markdown

getNextPage() can return the same page over and over, so a loop over pages never advances (description below, no linked issue).

The params of the previous request are stored in _params and merged on top of the new ones (array_merge($params, $userParams)), so an older before_id / after_id replaces the new cursor, and an older page_size replaces the $pageSize argument. This happens when the first call already contained a cursor, and also with a plain all(): the second page stores its own before_id in _params, so the third request asks for the second page again.

The previous params are now the base, and the new cursor (plus $pageSize when given) is applied after them, in BaseService::getNextPageResources and UserService::getNextPageOfChildren. Other filters are still carried over, but the opposite cursor is dropped (after_id on before_id pages, before_id on children pages), since the API rejects a request with both. ReportService::all() now stores _params too, so ReportService::getNextPage gets the same fix and keeps params such as page_size.

Testing

Added test/EasyPost/PaginationTest.php, which uses the mocking utility and a request hook to check the params sent for the next page; its tests fail without the fix and pass with it. The existing cassettes replay unchanged with the new param order; they were not re-recorded, since that needs EasyPost API keys. Locally the full suite has 2 errors in WebhookTest because the PHP build used lacks intl (Normalizer). phpcs passes.

Pull Request Type

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Improvement (fixing a typo, updating readme, renaming a variable name, etc)

This change was prepared with the help of an AI coding assistant.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants