Skip to content

Commit

Permalink
Add specific exception for tenant get
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkkul committed Nov 25, 2024
1 parent 58a7e8f commit 7a44a50
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
23 changes: 15 additions & 8 deletions weaviate/collections/grpc/tenants.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
from typing import Optional, Sequence, cast

from grpc.aio import AioRpcError # type: ignore

from weaviate.collections.classes.config import ConsistencyLevel
from weaviate.collections.classes.tenants import TenantActivityStatus
from weaviate.collections.grpc.retry import _Retry
from weaviate.collections.grpc.shared import _BaseGRPC
from weaviate.connect import ConnectionV4
from weaviate.exceptions import WeaviateTenantGetError
from weaviate.proto.v1 import tenants_pb2


Expand All @@ -25,14 +28,18 @@ async def get(self, names: Optional[Sequence[str]]) -> tenants_pb2.TenantsGetRep
collection=self._name,
names=tenants_pb2.TenantNames(values=names) if names is not None else None,
)
res = await _Retry().with_exponential_backoff(
0,
f"Get tenants for collection {self._name}",
self._connection.grpc_stub.TenantsGet,
request,
metadata=self._connection.grpc_headers(),
timeout=self._connection.timeout_config.query,
)
try:
res = await _Retry().with_exponential_backoff(
0,
f"Get tenants for collection {self._name}",
self._connection.grpc_stub.TenantsGet,
request,
metadata=self._connection.grpc_headers(),
timeout=self._connection.timeout_config.query,
)
except AioRpcError as e:
raise WeaviateTenantGetError(str(e))

return cast(tenants_pb2.TenantsGetReply, res)

def map_activity_status(self, status: tenants_pb2.TenantActivityStatus) -> TenantActivityStatus:
Expand Down
8 changes: 8 additions & 0 deletions weaviate/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,14 @@ def __init__(self, message: str):
self.message = message


class WeaviateTenantGetError(WeaviateQueryError):
"""Is raised if a gRPC tenant get request to Weaviate fails in any way."""

def __init__(self, message: str):
super().__init__(message, "tenant get")
self.message = message


class WeaviateAddInvalidPropertyError(WeaviateBaseError):
"""Is raised when adding an invalid new property."""

Expand Down

0 comments on commit 7a44a50

Please sign in to comment.