Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENH]: Improve tenant and DB validation handling #1494

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions chromadb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"UpdateCollectionMetadata",
"QueryResult",
"GetResult",
"__version__",
]

logger = logging.getLogger(__name__)
Expand Down
16 changes: 11 additions & 5 deletions chromadb/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

from overrides import override
import requests

from chromadb import __version__ as local_chroma_version
from chromadb.api import AdminAPI, ClientAPI, ServerAPI
from chromadb.api.types import (
CollectionMetadata,
Expand Down Expand Up @@ -141,10 +143,9 @@ def __init__(
self.database = database
# Create an admin client for verifying that databases and tenants exist
self._admin_client = AdminClient.from_system(self._system)
self._validate_tenant_database(tenant=tenant, database=database)

# Get the root system component we want to interact with
self._server = self._system.instance(ServerAPI)
self._validate_tenant_database(tenant=tenant, database=database)

# Submit event for a client start
telemetry_client = self._system.instance(ProductTelemetryClient)
Expand Down Expand Up @@ -425,7 +426,11 @@ def set_database(self, database: str) -> None:

def _validate_tenant_database(self, tenant: str, database: str) -> None:
try:
self._admin_client.get_tenant(name=tenant)
try:
self._admin_client.get_tenant(name=tenant)
except Exception as e1:
print(type(e1))
raise e1
except requests.exceptions.ConnectionError:
raise ValueError(
"Could not connect to a Chroma server. Are you sure it is running?"
Expand All @@ -437,8 +442,9 @@ def _validate_tenant_database(self, tenant: str, database: str) -> None:
)
if ex.response.status_code == 404:
raise ValueError(
f"It appears your Chroma server is running an older version of Chroma {self.get_version()}. "
"Please upgrade to the latest version."
f"It appears you are using newer version of Chroma client (v{local_chroma_version}) "
f"that is not compatible with Chroma server (v{self.get_version()}). "
"Please upgrade your server to the latest version."
)
else:
raise ValueError(
Expand Down
5 changes: 1 addition & 4 deletions chromadb/api/fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,4 @@ def raise_chroma_error(resp: requests.Response) -> None:
if chroma_error:
raise chroma_error

try:
resp.raise_for_status()
except requests.HTTPError:
raise (Exception(resp.text))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed wrapping specific error (HTTP) into a generic Exception wrapper.

resp.raise_for_status()