Skip to content

Commit 9288438

Browse files
committed
Change get_by_name to use TenantGetOne REST endpoint
motivation due to the filtering behaviour of `rpc.TenantsGet` that must remain, alternative would be adding `rpc.TenantsGetOne`
1 parent 5f08a35 commit 9288438

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

weaviate/collections/tenants/tenants.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -307,20 +307,24 @@ 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")
311310
if self._validate_arguments:
312311
_validate_input(
313312
_ValidateArgument(expected=[Union[str, Tenant]], name="tenant", value=tenant)
314313
)
315-
response = await self._grpc.get(
316-
names=[tenant.name if isinstance(tenant, Tenant) else tenant]
314+
tenant_name = tenant.name if isinstance(tenant, Tenant) else tenant
315+
response = await self._connection.get(
316+
path=f"/schema/{self._name}/tenants/{tenant_name}",
317+
error_msg=f"Could not get tenant {tenant_name} for collection {self._name}",
318+
status_codes=_ExpectedStatusCodes(
319+
ok_in=[200, 404], error=f"Get tenant {tenant_name} for collection {self._name}"
320+
),
317321
)
318-
if len(response.tenants) == 0:
322+
if response.status_code == 404:
319323
return None
320-
return Tenant(
321-
name=response.tenants[0].name,
322-
activity_status=self._grpc.map_activity_status(response.tenants[0].activity_status),
323-
)
324+
data = response.json()
325+
if not data:
326+
return None
327+
return Tenant(**data)
324328

325329
async def update(
326330
self, tenants: Union[TenantUpdateInputType, Sequence[TenantUpdateInputType]]

0 commit comments

Comments
 (0)