Skip to content

Commit 122b475

Browse files
committed
Handle get_by_name for <1.28.0 when the GET endpoint wasn't available
1 parent 9288438 commit 122b475

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

weaviate/collections/tenants/tenants.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -307,11 +307,22 @@ async def get_by_name(self, tenant: Union[str, Tenant]) -> Optional[TenantOutput
307307
`weaviate.UnexpectedStatusCodeError`
308308
If Weaviate reports a non-OK status.
309309
"""
310+
self._connection._weaviate_version.check_is_at_least_1_25_0("The 'get_by_name' method")
310311
if self._validate_arguments:
311312
_validate_input(
312313
_ValidateArgument(expected=[Union[str, Tenant]], name="tenant", value=tenant)
313314
)
314315
tenant_name = tenant.name if isinstance(tenant, Tenant) else tenant
316+
if self._connection._weaviate_version.is_lower_than(1, 28, 0):
317+
# For Weaviate versions < 1.28.0, we need to use the gRPC API
318+
# such versions don't have RBAC so the filtering issue doesn't exist therein
319+
tenants = await self.__get_with_grpc([tenant_name])
320+
if len(tenants) == 0:
321+
return None
322+
return tenants[tenant_name]
323+
# For Weaviate versions >= 1.28.0, we need to use the REST API
324+
# as the gRPC API filters out tenants that are not accessible to the user
325+
# due to RBAC requirements
315326
response = await self._connection.get(
316327
path=f"/schema/{self._name}/tenants/{tenant_name}",
317328
error_msg=f"Could not get tenant {tenant_name} for collection {self._name}",
@@ -321,10 +332,7 @@ async def get_by_name(self, tenant: Union[str, Tenant]) -> Optional[TenantOutput
321332
)
322333
if response.status_code == 404:
323334
return None
324-
data = response.json()
325-
if not data:
326-
return None
327-
return Tenant(**data)
335+
return Tenant(**response.json())
328336

329337
async def update(
330338
self, tenants: Union[TenantUpdateInputType, Sequence[TenantUpdateInputType]]

0 commit comments

Comments
 (0)