s3vectors: refuse indexed key calls when no engine is configured

A Server built without a vector engine client (as the admin's tests
build it) panicked on MetadataKeys instead of answering with an error.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011UpvafvK8JpagF94MHWqwK
This commit is contained in:
Chris LuandClaude Opus 5.5 committed 2026-11-19 23:00:16 -08:00
1 parent c3c1b3f53c
commit 70eab6844b
2 files changed
+28

No files matched your search

+17
View File
@@ -24,6 +24,9 @@ func (s *Server) MetadataKeys(ctx context.Context, bucket, index string) (*vecto
if _, err := s.trustedIndex(ctx, bucket, index); err != nil {
return nil, err
}
if !s.hasEngine() {
return nil, errNoEngine
}
return s.vectors.MetadataKeys(ctx, &vector_pb.MetadataKeysRequest{Table: tableID(bucket, index)})
}
@@ -35,6 +38,9 @@ func (s *Server) UpdateMetadataKey(ctx context.Context, bucket, index, key strin
if err != nil {
return nil, err
}
if !s.hasEngine() {
return nil, errNoEngine
}
if !remove {
if err := metadataKeyIndexable(idx, key); err != nil {
return nil, err
@@ -50,6 +56,17 @@ func (s *Server) UpdateMetadataKey(ctx context.Context, bucket, index, key strin
})
}
var errNoEngine = fmt.Errorf("no vector engine is configured")
// hasEngine reports whether calls can reach an engine client.
func (s *Server) hasEngine() bool {
backend := s.vectors
if described, ok := backend.(*describedClient); ok {
backend = described.VectorServiceClient
}
return backend != nil
}
func (s *Server) trustedIndex(ctx context.Context, bucket, index string) (*Index, error) {
var record map[string]interface{}
if err := s.internalCatalog(ctx, "GetTable", &s3tables.GetTableRequest{
@@ -60,3 +60,14 @@ func TestMetadataKeyIndexable(t *testing.T) {
t.Fatal(err)
}
}
func TestMetadataKeysWithoutAnEngine(t *testing.T) {
s := &Server{}
if s.hasEngine() {
t.Fatal("a server without a client has an engine")
}
s.vectors = &describedClient{}
if s.hasEngine() {
t.Fatal("a describe wrapper around no client has an engine")
}
}