Skip to content

fix: paginate worker deployments from nested result - #2819

Open
airshakur88 wants to merge 1 commit into
cloudflare:mainfrom
airshakur88:fix/deployment-list-pagination
Open

airshakur88 wants to merge 1 commit into
cloudflare:mainfrom
airshakur88:fix/deployment-list-pagination

Conversation

@airshakur88

@airshakur88 airshakur88 commented Nov 10, 2026 •

Copy link
Copy Markdown

Summary

  • Read deployment records from the API result.deployments field for iteration and async pagination.
  • Preserve page-number progression and expose deployments on the typed page result.
  • Add a regression test covering nested results and page 2 requests.

Fixes #2805

Verification

  • bun run jest tests/api-resources/workers/deployments-pagination.test.ts --runInBand
  • bun run tsc --noEmit --pretty false
  • bun run prettier --check src/resources/workers/scripts/deployments.ts src/lib/worker-deployments-page.ts tests/api-resources/workers/deployments-pagination.test.ts

@mangeshraut712 mangeshraut712 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading result.deployments is the right fix for this list endpoint, and the test shows the second page is requested. Two edge cases around an empty or already-final result are untested.

}

getPaginatedItems(): Item[] {
return this.result.deployments;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.result = body.result || { deployments: [] } only substitutes when result is missing or falsy. A body like { result: {}, result_info: { page: 1 } } is truthy, so getPaginatedItems() returns undefined and a for await over the list will throw. I'd use body.result?.deployments ?? [] (and keep a definite array on this.result).

nextPageRequestOptions also never returns null and increments query.page (defaulting a missing param to 1) instead of this.result_info.page. That is fine if AbstractPage stops on an empty items array, which the test relies on by serving a second page with deployments: []. If a last page still has items, or if the helper only stops when this method returns null, iteration would request page n+1 forever. I'd return null when the current page has fewer than per_page items, or when result_info.page is already the last page (if the API exposes a total), and add a test where result is {} and one where the first page is the last page.

@mangeshraut712 mangeshraut712 left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Withdrawn: duplicate of my earlier review.

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.

workers.scripts.deployments.list() paginates the wrong field in v7.2.0

2 participants