Skip to content
Open
Changes from all commits
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
23 changes: 18 additions & 5 deletions chromadb/auth/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,18 @@ def _singleton_tenant_database_if_applicable(
if user_tenant and user_tenant != "*":
tenant = user_tenant
if user_databases:
user_databases_set = set(user_databases)
if len(user_databases_set) == 1 and "*" not in user_databases_set:
database = list(user_databases_set)[0]
unique_db = None
for db in user_databases:
if db == "*":
unique_db = None
break
if unique_db is None:
unique_db = db
elif db != unique_db:
unique_db = None
break
if unique_db is not None:
database = unique_db
return tenant, database


Expand Down Expand Up @@ -65,14 +74,18 @@ def maybe_set_tenant_and_database(
and new_tenant
and new_tenant != user_provided_tenant
):
raise ChromaAuthError(f"Tenant {user_provided_tenant} does not match {new_tenant} from the server. Are you sure the tenant is correct?")
raise ChromaAuthError(
f"Tenant {user_provided_tenant} does not match {new_tenant} from the server. Are you sure the tenant is correct?"
)
if (
user_provided_database
and user_provided_database != DEFAULT_DATABASE
and new_database
and new_database != user_provided_database
):
raise ChromaAuthError(f"Database {user_provided_database} does not match {new_database} from the server. Are you sure the database is correct?")
raise ChromaAuthError(
f"Database {user_provided_database} does not match {new_database} from the server. Are you sure the database is correct?"
)

if (
not user_provided_tenant or user_provided_tenant == DEFAULT_TENANT
Expand Down