Skip to content

[v2] pagination: Add KeyedPage interface - #3971

Merged
winiciusallan merged 2 commits into
v2from
bp-v2-cd90e85-50e5c69
Aug 20, 2026
Merged

winiciusallan merged 2 commits into
v2from
bp-v2-cd90e85-50e5c69

Conversation

@gophercloud-backport-bot

Copy link
Copy Markdown

Backport: #3947

Currently, pagination of list resources works by scanning resource bodies, looking for the first non-"links" resource key. This mostly works but is crude. It also doesn't work for resources that have multiple non-"links" top-level keys, such as placement's list resource provider inventories API, which has both an inventories envelope key and a separate resource_provider_generation key.

Improve this by adding a new KeyedPage interface, with a ResourceKey() string value. When a Page struct implements this interface, the static key will be used rather than us scanning the body for the key. When this interface is not implemented, we continue to fallback to the old heuristic. The latter will allow us to implement the interface incrementally, and we only do it here for NetworkPage in openstack/networking/v2/networks/results.go.

Commit 0e6c7c7 (#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]>
Currently, pagination of list resources works by scanning resource
bodies, looking for the first non-"links" resource key. This mostly
works but is crude. It also doesn't work for resources that have
multiple non-"links" top-level keys, such as placement's list resource
provider inventories API, which has both a 'inventories' envelope key
and a separate 'resource_provider_generation' key [1].

Improve this by adding a new KeyedPage interface, with a ResourceKey()
string value. When a Page struct implements this interface, the static
key will be used rather than us scanning the body for the key. When this
interface is *not* implemented, we continue to fallback to the old
heuristic. The latter will allow us to implement the interface
incrementally, and we only do it here for NetworkPage in
openstack/networking/v2/networks/results.go.

[1] https://docs.openstack.org/api-ref/placement/#list-resource-provider-inventories

Signed-off-by: Stephen Finucane <[email protected]>
@github-actions github-actions Bot added edit:networking This PR updates networking code v2 This PR targets v2 edit:gophercloud This PR updates common Gophercloud code semver:minor Backwards-compatible change labels Aug 20, 2026
@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 63.935% (+0.002%) from 63.933% — bp-v2-cd90e85-50e5c69 into v2

@winiciusallan
winiciusallan merged commit a881d88 into v2 Aug 20, 2026
19 checks passed
@winiciusallan
winiciusallan deleted the bp-v2-cd90e85-50e5c69 branch August 20, 2026 13:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

edit:gophercloud This PR updates common Gophercloud code edit:networking This PR updates networking code semver:minor Backwards-compatible change v2 This PR targets v2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants