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

[BUG] UUID should be uuid type not str #1644

Merged
merged 1 commit into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion chromadb/auth/fastapi_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from functools import partial
from typing import Any, Callable, Dict, Optional, Sequence, cast
from chromadb.server.fastapi.utils import string_to_uuid
from chromadb.api import ServerAPI
from chromadb.auth import AuthzResourceTypes

Expand Down Expand Up @@ -46,7 +47,7 @@ def attr_from_collection_lookup(
def _wrap(**kwargs: Any) -> Dict[str, Any]:
_api = cast(ServerAPI, kwargs["api"])
col = _api.get_collection(
id=kwargs["function_kwargs"][collection_id_arg])
id=string_to_uuid(kwargs["function_kwargs"][collection_id_arg]))
return {"tenant": col.tenant, "database": col.database}

return partial(_wrap, **kwargs)
10 changes: 1 addition & 9 deletions chromadb/server/fastapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
from chromadb.api import ServerAPI
from chromadb.errors import (
ChromaError,
InvalidUUIDError,
InvalidDimensionException,
InvalidHTTPVersion,
)
Expand All @@ -51,7 +50,7 @@

import logging

from chromadb.server.fastapi.utils import fastapi_json_response
from chromadb.server.fastapi.utils import fastapi_json_response, string_to_uuid as _uuid
from chromadb.telemetry.opentelemetry.fastapi import instrument_fastapi
from chromadb.types import Database, Tenant
from chromadb.telemetry.product import ServerContext, ProductTelemetryClient
Expand Down Expand Up @@ -96,13 +95,6 @@ async def check_http_version_middleware(
return await call_next(request)


def _uuid(uuid_str: str) -> UUID:
try:
return UUID(uuid_str)
except ValueError:
raise InvalidUUIDError(f"Could not parse {uuid_str} as a UUID")


class ChromaAPIRouter(fastapi.APIRouter): # type: ignore
# A simple subclass of fastapi's APIRouter which treats URLs with a trailing "/" the
# same as URLs without. Docs will only contain URLs without trailing "/"s.
Expand Down
9 changes: 8 additions & 1 deletion chromadb/server/fastapi/utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
from uuid import UUID
from starlette.responses import JSONResponse

from chromadb.errors import ChromaError
from chromadb.errors import ChromaError, InvalidUUIDError


def fastapi_json_response(error: ChromaError) -> JSONResponse:
return JSONResponse(
content={"error": error.name(), "message": error.message()},
status_code=error.code(),
)

def string_to_uuid(uuid_str: str) -> UUID:
try:
return UUID(uuid_str)
except ValueError:
raise InvalidUUIDError(f"Could not parse {uuid_str} as a UUID")
Loading