From 0ca8b1960cb70deaecffe056570d91aacb8e82bd Mon Sep 17 00:00:00 2001 From: Syngnat Date: Fri, 17 Jul 2026 17:06:08 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(milvus):=20=E5=85=BC?= =?UTF-8?q?=E5=AE=B9=E4=B8=8D=E6=94=AF=E6=8C=81=E6=95=B0=E6=8D=AE=E5=BA=93?= =?UTF-8?q?=E6=9E=9A=E4=B8=BE=E7=9A=84=E6=9C=8D=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 数据库列表接口不可用时验证当前数据库的集合枚举能力 - 验证成功后回退到已配置数据库并继续加载集合 - 补充测试连接成功但侧栏展开失败的回归用例 --- internal/db/milvus_impl.go | 4 ++++ internal/db/milvus_impl_test.go | 38 +++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/internal/db/milvus_impl.go b/internal/db/milvus_impl.go index 6c8d21c0..fc0fe2a5 100644 --- a/internal/db/milvus_impl.go +++ b/internal/db/milvus_impl.go @@ -200,6 +200,10 @@ func (m *MilvusDB) GetDatabases() ([]string, error) { var raw interface{} if err := m.doJSON(ctx, http.MethodPost, milvusDatabasesListPath, map[string]interface{}{}, &raw); err != nil { + if _, fallbackErr := m.listCollections(ctx, m.database); fallbackErr == nil { + logger.Warnf("Milvus 数据库列表接口不可用,回退到当前数据库 %s: %v", m.database, err) + return []string{m.database}, nil + } return nil, err } names := milvusNamesFromValue(raw, "dbNames", "databases", "names") diff --git a/internal/db/milvus_impl_test.go b/internal/db/milvus_impl_test.go index c8b82af0..d8e0e0af 100644 --- a/internal/db/milvus_impl_test.go +++ b/internal/db/milvus_impl_test.go @@ -136,6 +136,44 @@ func TestMilvusGetDatabasesPostsJSONObject(t *testing.T) { } } +func TestMilvusGetDatabasesFallsBackWhenDatabaseListIsUnsupported(t *testing.T) { + collectionListCalls := 0 + server := newMockMilvusServer(t, func(w http.ResponseWriter, r *http.Request) { + switch { + case isMilvusCollectionListRequest(r): + collectionListCalls++ + if body := decodeMilvusRequest(t, r); body["dbName"] != defaultMilvusDatabase { + t.Fatalf("list body = %#v", body) + } + writeMilvusJSON(w, []string{"products"}) + case r.Method == http.MethodPost && r.URL.Path == milvusDatabasesListPath: + http.NotFound(w, r) + default: + w.WriteHeader(http.StatusNotFound) + } + }) + + db := newTestMilvusDB(t, server.URL) + databases, err := db.GetDatabases() + if err != nil { + t.Fatalf("GetDatabases should fall back to the configured database: %v", err) + } + if strings.Join(databases, ",") != defaultMilvusDatabase { + t.Fatalf("databases = %v, want [%s]", databases, defaultMilvusDatabase) + } + + tables, err := db.GetTables(databases[0]) + if err != nil { + t.Fatalf("GetTables failed after database fallback: %v", err) + } + if strings.Join(tables, ",") != "products" { + t.Fatalf("tables = %v, want [products]", tables) + } + if collectionListCalls != 3 { + t.Fatalf("collection list calls = %d, want 3", collectionListCalls) + } +} + func TestMilvusGetTablesUsesRESTV2CollectionList(t *testing.T) { server := newMockMilvusServer(t, func(w http.ResponseWriter, r *http.Request) { if isMilvusCollectionListRequest(r) {