Skip to content

Skip status and kind filters when all given values are empty - #7099

Open
vipulpandey21 wants to merge 1 commit into
pipe-cd:masterfrom
vipulpandey21:fix/list-deployments-empty-status-panic
Open

Skip status and kind filters when all given values are empty#7099
vipulpandey21 wants to merge 1 commit into
pipe-cd:masterfrom
vipulpandey21:fix/list-deployments-empty-status-panic

Conversation

@vipulpandey21

@vipulpandey21 vipulpandey21 commented Jul 31, 2026

Copy link
Copy Markdown

What this PR does:

In APIService.ListDeployments, the status and kind filters are added only when at least one usable value was collected, instead of reading statuses[0] / kinds[0] on a slice that can be empty.

+		// Empty values are skipped above, so the request may contain no usable
+		// status at all. In that case no status filter should be added.
+		if len(statuses) > 0 {
 			filters = append(filters, datastore.ListFilter{
 				Field:    "Status",
 				Operator: datastore.OperatorEqual,
 				Value:    statuses[0],
 			})
+		}

Same guard for kinds. Behaviour is unchanged when a valid value is given.

Why we need it:

The loop right above already skips empty values, so a request like statuses: [""] leaves the slice empty and the index access panics with index out of range [0] with length 0. The API server has no recovery interceptor, so the panic stops the whole control plane process, not just that request. It is reachable with pipectl deployment list --status=,. Full details and how I checked it are in #7098.

I only added the two guards. I did not change how empty values are treated, since both the handler and pipectl already skip them on purpose.

How I tested it

Added TestListDeploymentsFilters, which checks which filters actually reach the datastore.

Without the fix it reproduces the panic at the old line:

--- FAIL: TestListDeploymentsFilters/ok:_statuses_holding_only_empty_values_adds_no_status_filter
panic: runtime error: index out of range [0] with length 0
    .../pkg/app/server/grpcapi/api.go:553

With the fix:

--- PASS: TestListDeploymentsFilters
    --- PASS: .../ok:_no_optional_filter_is_given
    --- PASS: .../ok:_a_valid_status_is_used_as_a_filter
    --- PASS: .../ok:_statuses_holding_only_empty_values_adds_no_status_filter
    --- PASS: .../ok:_kinds_holding_only_empty_values_adds_no_kind_filter
    --- PASS: .../invalid:_unknown_deployment_status
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.

go vet on that package still prints two copies lock value warnings for RegisterEvent. Those are already on master without my change, so I left them alone.

Which issue(s) this PR fixes:

Fixes #7098

Does this PR introduce a user-facing change?:

  • How are users affected by this change: A request whose status or kind values are all empty is handled like no filter was given, instead of crashing the control plane.
  • Is this breaking change: No
  • How to migrate (if breaking change): Not applicable

The loop above skips empty values, so a request like statuses: [""]
leaves the slice empty and reading statuses[0] panics. The API server
has no recovery interceptor, so this stops the whole control plane.

Fixes pipe-cd#7098

Signed-off-by: Vipul Subhash Pandey <vipulpandey7917@gmail.com>
@vipulpandey21
vipulpandey21 requested a review from a team as a code owner July 31, 2026 05:03
@github-actions

Copy link
Copy Markdown
Contributor

👋 Hi @vipulpandey21, welcome to PipeCD and thanks for opening your first pull request!

We’re really happy to have you here

Before your PR gets merged, please check a few important things below.


Helpful resources


DCO Sign-off

All commits must include a Signed-off-by line to comply with the Developer Certificate of Origin (DCO).

In case you forget to sign-off your commit(s), follow these steps:

For the last commit:

git commit --amend --signoff
git push --force-with-lease

For multiple commits:

git rebase --signoff origin/master
git push --force-with-lease

Run checks locally

Before pushing updates, please run:

make check

This runs the same checks as CI and helps catch issues early.


💬 Need help?

If anything is unclear, feel free to ask in this PR or join us on the CNCF Slack in the #pipecd channel.
You can get your Slack invite from: https://communityinviter.com/apps/cloud-native/cncf

Thanks for contributing to PipeCD! ❤️

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.

ListDeployments panics when statuses or kinds contain only empty values

1 participant