Skip to content

pagination: Fix AllPages returning wrong key for empty linked pages - #3945

Merged
stephenfin merged 1 commit into
gophercloud:mainfrom
shiftstack:fix-paging
Aug 17, 2026
Merged

stephenfin merged 1 commit into
gophercloud:mainfrom
shiftstack:fix-paging

Conversation

@stephenfin

Copy link
Copy Markdown
Contributor

When AllPages() processes a linked page where all results are empty, EachPage returns early without invoking the callback (because IsEmpty returns true). This left the resource key unset (empty string ""), producing a body like {"": nil} instead of {"networks": []}.

This was harmless until b80f371 added validation in extractIntoPtr that correctly rejects responses missing the expected key, causing ExtractNetworks (and similar) to fail with "expected response key not found in response" on empty list results.

Fix by discovering the resource key from the first page body before calling EachPage, rather than inside the callback.

When AllPages() processes a linked page where all results are empty,
EachPage returns early without invoking the callback (because IsEmpty
returns true). This left the resource key unset (empty string ""),
producing a body like {"": nil} instead of {"networks": []}.

This was harmless until b80f371 added validation in extractIntoPtr
that correctly rejects responses missing the expected key, causing
ExtractNetworks (and similar) to fail with "expected response key
not found in response" on empty list results.

Fix by discovering the resource key from the first page body before
calling EachPage, rather than inside the callback.

Signed-off-by: Stephen Finucane <[email protected]>
Assisted-By: Claude Opus 4.6 <[email protected]>
@github-actions github-actions Bot added edit:gophercloud This PR updates common Gophercloud code semver:patch No API change backport-v2 This PR will be backported to v2 labels Aug 14, 2026
@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 63.549% (+0.005%) from 63.544% — shiftstack:fix-paging into gophercloud:main

@stephenfin

stephenfin commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor Author

I think this needs to be backported to v2. We're seeing similar issues in e.g. #3930

@mandre mandre left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@stephenfin
stephenfin added this pull request to the merge queue Aug 17, 2026
Merged via the queue into gophercloud:main with commit ae642c9 Aug 17, 2026
70 checks passed
@stephenfin
stephenfin deleted the fix-paging branch August 17, 2026 12:09
stephenfin added a commit to shiftstack/gophercloud that referenced this pull request Aug 19, 2026
Commit 0e6c7c7 (gophercloud#3945) ensured how we retrieve the key from a response
body, ensuring we don't get skip this if the page is empty. However, we
still re-evaluate the key for each page rather than using the key we
determined once. This is wasteful and unnecessary complexity. Fix it
now, ahead of the introduction of KeyedPage.

Signed-off-by: Stephen Finucane <[email protected]>
winiciusallan pushed a commit to shiftstack/gophercloud that referenced this pull request Aug 20, 2026
Commit 0e6c7c7 (gophercloud#3945) ensured how we retrieve the key from a response
body, ensuring we don't get skip this if the page is empty. However, we
still re-evaluate the key for each page rather than using the key we
determined once. This is wasteful and unnecessary complexity. Fix it
now, ahead of the introduction of KeyedPage.

Signed-off-by: Stephen Finucane <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-v2 This PR will be backported to v2 edit:gophercloud This PR updates common Gophercloud code semver:patch No API change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants