Skip to content

Return the cursor when listing applications without label filter - #7101

Open
vipulpandey21 wants to merge 1 commit into
pipe-cd:masterfrom
vipulpandey21:fix/list-applications-missing-cursor
Open

Return the cursor when listing applications without label filter#7101
vipulpandey21 wants to merge 1 commit into
pipe-cd:masterfrom
vipulpandey21:fix/list-applications-missing-cursor

Conversation

@vipulpandey21

@vipulpandey21 vipulpandey21 commented Jul 31, 2026

Copy link
Copy Markdown

What this PR does:

Sets the Cursor field on the response APIService.ListApplications returns when the request has no label filter.

 	if len(req.Labels) == 0 {
 		return &apiservice.ListApplicationsResponse{
 			Applications: apps,
+			Cursor:       cursor,
 		}, nil
 	}

Why we need it:

That early return was the only path in the function that did not set the cursor, so a client without a label filter always received an empty cursor and could not ask for the next page. pipectl application list has a documented --cursor flag but there was no value to pass to it.

The other two returns in the same function set it, and ListDeployments sets it in the same situation. It also used to be set here before #4186 added label filtering. Details and the history I looked at are in #7100.

I kept this to the one line. The label filtering loop below it has its own paging behaviour, which I did not touch.

How I tested it

Added TestListApplicationsCursor covering both the no label and the with label case.

Without the fix the no label case fails:

--- FAIL: TestListApplicationsCursor/cursor_is_returned_when_no_label_filter_is_given
    Error:      Not equal:
                expected: "next-page-cursor"
                actual  : ""

With the fix:

--- PASS: TestListApplicationsCursor
    --- PASS: .../cursor_is_returned_when_no_label_filter_is_given
    --- PASS: .../cursor_is_returned_when_a_label_filter_is_given
ok  	github.com/pipe-cd/pipecd/pkg/app/server/grpcapi

go test ./pkg/app/server/grpcapi/... passes, and go build ./cmd/pipecd ./cmd/pipectl is fine.

One thing I wanted to be sure about before changing this: whether handing back a real cursor could make a client loop forever. It cannot, because applicationStore.List returns an empty cursor once there are no more records:

// In case there is no more elements found, cursor should be set to empty too.
if len(apps) == 0 {
    return apps, "", nil
}

So a client that loops until the cursor is empty still terminates.

Which issue(s) this PR fixes:

Fixes #7100

Does this PR introduce a user-facing change?:

  • How are users affected by this change: ListApplications and pipectl application list return a usable cursor when no label filter is given, so paging past the first page works. A client that loops until the cursor is empty now walks through all applications instead of stopping after the first page.
  • Is this breaking change: No
  • How to migrate (if breaking change): Not applicable

ListApplications returns early when no label filter is given, and that
path was not setting the Cursor field, so clients could never move to
the next page. ListDeployments sets it in the same situation.

Fixes pipe-cd#7100

Signed-off-by: Vipul Subhash Pandey <vipulpandey7917@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ListApplications does not return the cursor when no label filter is given

1 participant