Skip to content
Open
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
20 changes: 20 additions & 0 deletions mock_tests/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,26 @@ def test_collection_exists(weaviate_mock: HTTPServer) -> None:
assert e.value.status_code == 500


@pytest.mark.asyncio
async def test_async_collection_exists(weaviate_mock: HTTPServer) -> None:
non_existing = "NonExistingCollection"
erroring = "ErroringCollection"
weaviate_mock.expect_request(f"/v1/schema/{non_existing}").respond_with_json(
response_json={"error": [{"message": "collection not found"}]}, status=404
)
weaviate_mock.expect_request(f"/v1/schema/{erroring}").respond_with_json(
response_json={"error": [{"message": "this is an error"}]}, status=500
)

async with weaviate.use_async_with_local(
port=MOCK_PORT, host=MOCK_IP, grpc_port=MOCK_PORT_GRPC, skip_init_checks=True
) as client:
assert not await client.collections.use(non_existing).exists()
with pytest.raises(weaviate.exceptions.UnexpectedStatusCodeError) as e:
await client.collections.use(erroring).exists()
assert e.value.status_code == 500


def test_grpc_client_version_header(
metadata_capture_collection: tuple[
weaviate.collections.Collection, MockMetadataCaptureWeaviateService
Expand Down
7 changes: 5 additions & 2 deletions weaviate/collections/collection/async_.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from weaviate.collections.query import _QueryCollectionAsync
from weaviate.collections.tenants import _TenantsAsync
from weaviate.connect.v4 import ConnectionAsync
from weaviate.exceptions import UnexpectedStatusCodeError
from weaviate.types import UUID

from .base import _CollectionBase
Expand Down Expand Up @@ -183,8 +184,10 @@ async def exists(self) -> bool:
try:
await self.config.get(simple=True)
return True
except Exception:
return False
except UnexpectedStatusCodeError as e:
if e.status_code == 404:
return False
raise e

async def shards(self) -> List[Shard]:
"""Get the statuses of all the shards of this collection.
Expand Down