fix: chroma has_collection always returns False (name vs Collection) (#25780)

has_collection did `collection_name in self.client.list_collections()`,
but chromadb's list_collections() returns Collection objects (1.x), not
name strings — so the membership test is always False, even when the
collection exists. Compare against the collection names instead (with a
hasattr guard tolerating versions that yield plain names).

Found via the dependency-contract test suite (unit/deps/test_chromadb.py).
This commit is contained in:
Classic298
2026-06-29 02:15:05 -05:00
committed by GitHub
parent 342539f1e1
commit 15d96b1f2a
@@ -57,7 +57,11 @@ class ChromaClient(VectorDBBase):
def has_collection(self, collection_name: str) -> bool:
# Check if the collection exists based on the collection name.
collection_names = self.client.list_collections()
# chromadb's list_collections() returns Collection objects (1.x), so a
# bare `name in collections` membership test is always False — compare
# against the names. (hasattr guard tolerates versions that yield names.)
collections = self.client.list_collections()
collection_names = [c.name if hasattr(c, 'name') else c for c in collections]
return collection_name in collection_names
def delete_collection(self, collection_name: str):