Skip to content

Commit

Permalink
Defer fastapi type imports in auth (#1557)
Browse files Browse the repository at this point in the history
## Description of changes

*Summarize the changes made by this PR.*
 - Improvements & Bug fixes
- Defer fastapi type imports in auth code so as not to get a circular
import. Fixes #1554

## Test plan
*How are these changes tested?*

- [x] Tests pass locally with `pytest` for python, `yarn test` for js

## Documentation Changes
*Are all docstrings for user-facing APIs updated if required? Do we need
to make documentation changes in the [docs
repository](https://github.com/chroma-core/docs)?*
  • Loading branch information
beggers authored Dec 20, 2023
1 parent a0b99fb commit f3ee98f
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions chromadb/auth/fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@
from starlette.responses import Response
from starlette.types import ASGIApp

from chromadb.server.fastapi.types import (
CreateDatabase,
CreateTenant,
)

from chromadb.config import DEFAULT_TENANT, System
from chromadb.auth import (
AuthorizationContext,
Expand Down Expand Up @@ -226,14 +221,14 @@ def wrapped(*args: Any, **kwargs: Dict[Any, Any]) -> Any:
if desired_tenant and "tenant" in kwargs:
if isinstance(kwargs["tenant"], str):
kwargs["tenant"] = desired_tenant
elif isinstance(kwargs["tenant"], CreateTenant):
elif isinstance(kwargs["tenant"], chromadb.server.fastapi.types.CreateTenant):
kwargs["tenant"].name = desired_tenant
databases = request.state.user_identity.get_user_databases()
if databases and len(databases) == 1 and "database" in kwargs:
desired_database = databases[0]
if isinstance(kwargs["database"], str):
kwargs["database"] = desired_database
elif isinstance(kwargs["database"], CreateDatabase):
elif isinstance(kwargs["database"], chromadb.server.fastapi.types.CreateDatabase):
kwargs["database"].name = desired_database

return f(*args, **kwargs)
Expand Down

0 comments on commit f3ee98f

Please sign in to comment.