Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions chromadb/api/async_fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,15 @@ def _get_client(self) -> httpx.AsyncClient:
+ " (https://github.com/chroma-core/chroma)"
)

self._clients[loop_hash] = httpx.AsyncClient(
timeout=None,
headers=headers,
verify=self._settings.chroma_server_ssl_verify or False,
limits=self.http_limits,
)
client_kwargs = {
"timeout": None,
"headers": headers,
"limits": self.http_limits,
}
if self._settings.chroma_server_ssl_verify is not None:
client_kwargs["verify"] = self._settings.chroma_server_ssl_verify

self._clients[loop_hash] = httpx.AsyncClient(**client_kwargs)

return self._clients[loop_hash]

Expand Down
31 changes: 31 additions & 0 deletions chromadb/test/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from chromadb.api import ClientAPI
import chromadb.server.fastapi
from chromadb.api.fastapi import FastAPI
from chromadb.api.async_fastapi import AsyncFastAPI
import pytest
import tempfile
import os
Expand Down Expand Up @@ -199,6 +200,36 @@ def test_fastapi_uses_http_limits_from_settings() -> None:
assert captured["verify"] is True


@pytest.mark.parametrize("ssl_verify", [None, False, True, "/path/to/ca.pem"])
def test_async_fastapi_passes_ssl_verify_only_when_configured(ssl_verify: Any) -> None:
settings = Settings(
chroma_api_impl="chromadb.api.async_fastapi.AsyncFastAPI",
chroma_server_host="localhost",
chroma_server_http_port=9000,
chroma_server_ssl_verify=ssl_verify,
)
system = System(settings)
captured: Dict[str, Any] = {}

def factory(**kwargs: Any) -> Any:
captured.update(kwargs)
return MagicMock()

AsyncFastAPI._clients.clear()
with patch.object(AsyncFastAPI, "require", side_effect=[MagicMock(), MagicMock()]):
with patch("chromadb.api.async_fastapi.httpx.AsyncClient", side_effect=factory):
api = AsyncFastAPI(system)
api._get_client()

assert captured["timeout"] is None
assert captured["headers"]["Content-Type"] == "application/json"
if ssl_verify is None:
assert "verify" not in captured
else:
assert captured["verify"] == ssl_verify
AsyncFastAPI._clients.clear()


def test_persistent_client_close() -> None:
"""Test that close() properly releases resources in PersistentClient."""
if os.environ.get("CHROMA_INTEGRATION_TEST_ONLY"):
Expand Down