Skip to content

Commit 7a44a50

Browse files
committed
Add specific exception for tenant get
1 parent 58a7e8f commit 7a44a50

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

weaviate/collections/grpc/tenants.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
from typing import Optional, Sequence, cast
22

3+
from grpc.aio import AioRpcError # type: ignore
4+
35
from weaviate.collections.classes.config import ConsistencyLevel
46
from weaviate.collections.classes.tenants import TenantActivityStatus
57
from weaviate.collections.grpc.retry import _Retry
68
from weaviate.collections.grpc.shared import _BaseGRPC
79
from weaviate.connect import ConnectionV4
10+
from weaviate.exceptions import WeaviateTenantGetError
811
from weaviate.proto.v1 import tenants_pb2
912

1013

@@ -25,14 +28,18 @@ async def get(self, names: Optional[Sequence[str]]) -> tenants_pb2.TenantsGetRep
2528
collection=self._name,
2629
names=tenants_pb2.TenantNames(values=names) if names is not None else None,
2730
)
28-
res = await _Retry().with_exponential_backoff(
29-
0,
30-
f"Get tenants for collection {self._name}",
31-
self._connection.grpc_stub.TenantsGet,
32-
request,
33-
metadata=self._connection.grpc_headers(),
34-
timeout=self._connection.timeout_config.query,
35-
)
31+
try:
32+
res = await _Retry().with_exponential_backoff(
33+
0,
34+
f"Get tenants for collection {self._name}",
35+
self._connection.grpc_stub.TenantsGet,
36+
request,
37+
metadata=self._connection.grpc_headers(),
38+
timeout=self._connection.timeout_config.query,
39+
)
40+
except AioRpcError as e:
41+
raise WeaviateTenantGetError(str(e))
42+
3643
return cast(tenants_pb2.TenantsGetReply, res)
3744

3845
def map_activity_status(self, status: tenants_pb2.TenantActivityStatus) -> TenantActivityStatus:

weaviate/exceptions.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,14 @@ def __init__(self, message: str):
249249
self.message = message
250250

251251

252+
class WeaviateTenantGetError(WeaviateQueryError):
253+
"""Is raised if a gRPC tenant get request to Weaviate fails in any way."""
254+
255+
def __init__(self, message: str):
256+
super().__init__(message, "tenant get")
257+
self.message = message
258+
259+
252260
class WeaviateAddInvalidPropertyError(WeaviateBaseError):
253261
"""Is raised when adding an invalid new property."""
254262

0 commit comments

Comments
 (0)