Skip to content

NextCursorPage auto-pagination stops on empty pages with a next cursor #890

Description

@sylvesterkaczmarek

Summary

NextCursorPage can carry an explicit server-provided next cursor, but both GetNextPage() and the auto-pager currently stop as soon as the current page has an empty data array.

That means an empty first or intermediate page silently terminates iteration even when has_more is true and next points to a later page containing results.

This is observable through public endpoints using NextCursorPage, including Admin.Organization.Groups.ListAutoPaging.

Reproduction

Using a custom HTTP client, return these pages from Admin.Organization.Groups.ListAutoPaging:

GET /organization/groups
{"data":[],"has_more":true,"next":"cursor-1"}

GET /organization/groups?after=cursor-1
{"data":[{"id":"group-1","created_at":1,"group_type":"group","is_scim_managed":false,"name":"one"}],"has_more":false,"next":null}

On current main, auto-pagination yields no groups and makes only the first request.

The same happens for an empty intermediate page:

page 1: data=[group-1], next=cursor-1
page 2: data=[],        next=cursor-2
page 3: data=[group-2], terminal

Current result is only group-1; page 3 is never requested.

Root cause

NextCursorPage.GetNextPage() returns early on len(r.Data) == 0 before consulting HasMore or Next, and NextCursorPageAutoPager.Next() has the same empty-data termination check.

For explicit-next pagination, the continuation token is the pagination authority. An empty result page does not necessarily mean there is no next page.

Expected behavior

NextCursorPage auto-pagination should follow a non-empty next cursor through empty first or intermediate pages. It should still stop normally when has_more is explicitly false or when no next cursor is provided.

Ordinary populated-page behavior should remain unchanged.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions