Skip to content

docstore/awsdynamodb: fix panic on empty in/not-in filter value - #3754

Merged
vangent merged 1 commit into
google:masterfrom
herdiyana256:fix-awsdynamodb-empty-in-filter-panic
Jul 23, 2026
Merged

docstore/awsdynamodb: fix panic on empty in/not-in filter value#3754
vangent merged 1 commit into
google:masterfrom
herdiyana256:fix-awsdynamodb-empty-in-filter-panic

Conversation

@herdiyana256

Copy link
Copy Markdown
Contributor

toInCondition unconditionally does vslice.Index(0) on the filter value:

https://github.com/google/go-cloud/blob/master/docstore/awsdynamodb/v2/query.go#L449

docstore's own Where() validator (validFilterSlice, in docstore/query.go) accepts an empty slice as a valid value for the in/not-in operators, since its bounds-check loop never executes for a zero-length slice. A query built with an empty slice, e.g. Where("category", "in", []string{}), reaches toInCondition with a zero-length slice and panics with "reflect: slice index out of range" during query planning, before any network call, with nothing in docstore or this package recovering it.

This handles the zero-length case by building an always-false condition instead of indexing into the empty slice. Not() of that gives an always-true condition for not-in, matching the usual "x IN ()" / "x NOT IN ()" semantics (consistent with how mongodocstore's $in/$nin already treats an empty list).

Added a regression test. go test ./docstore/... passes.

toInCondition unconditionally indexed into the filter value slice
(vslice.Index(0)) without checking its length. docstore's own
Where() validator (validFilterSlice) accepts an empty slice as a
valid value for the in/not-in operators, so a query built with an
empty slice (e.g. Where("x", "in", []string{})) panicked with
"reflect: slice index out of range" during query planning, with
no recover() anywhere in the call path.

Handle the empty case by building an always-false condition, which
Not() turns into always-true for not-in, matching how other docstore
backends (mongodocstore's $in/$nin, for example) already treat an
empty in-list.

go test ./docstore/... passes.
@codecov

codecov Bot commented Jul 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (master@0361726). Learn more about missing BASE report.
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##             master    #3754   +/-   ##
=========================================
  Coverage          ?   75.33%           
=========================================
  Files             ?      104           
  Lines             ?    14204           
  Branches          ?        0           
=========================================
  Hits              ?    10700           
  Misses            ?     2767           
  Partials          ?      737           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@vangent
vangent merged commit 44c31d0 into google:master Jul 23, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants