weaviate-python-client icon indicating copy to clipboard operation
weaviate-python-client copied to clipboard

async Collection.exists() still swallows all exceptions (PR #1950 fixed sync path only, async regression remains)

Open tsushanth opened this issue 4 months ago • 1 comments

Bug

async_collection.exists() in weaviate/collections/collection/async_.py catches all exceptions and returns False, making it impossible to distinguish "collection not found" from "connection error / auth failure / timeout":

async def exists(self) -> bool:
    try:
        await self.config.get(simple=True)
        return True
    except Exception:      # ← catches everything
        return False

Why this matters

A caller doing:

if not await collection.exists():
    await client.collections.create(...)

will silently try to create a collection every time the server is unreachable — which may succeed with wrong configuration, fail with a confusing error, or mask a network outage entirely.

Incomplete fix from PR #1950

Issue #1799 reported this exact problem. PR #1950 (merged Feb 2026) fixed the synchronous path in weaviate/collections/collection/sync.py:

# sync.py — correctly re-raises on non-404
except UnexpectedStatusCodeError as e:
    if e.status_code == 404:
        return False
    raise

But the async counterpart in async_.py was never updated and still has the bare except Exception: return False. A collaborator noted on the closed issue: "Pretty sure this was not fixed!" — and indeed it was not for the async client.

Suggested fix

Mirror the sync implementation exactly:

async def exists(self) -> bool:
    try:
        await self.config.get(simple=True)
        return True
    except UnexpectedStatusCodeError as e:
        if e.status_code == 404:
            return False
        raise

References

  • Issue #1799 (closed by PR #1950, sync-only fix)
  • PR #1950 — the sync fix that should have included the async path

tsushanth avatar Jul 23 '26 15:07 tsushanth

I'd like to work on this. Looking at the code, sync.py's exists() (lines 201-209) already handles this correctly by catching UnexpectedStatusCodeError and only swallowing 404s — I'll mirror that exact pattern into async_.py's exists(). I also noticed there's no existing test coverage for exists() on either the sync or async path, which is likely how the async gap in #1950 went unnoticed — I'll add tests for both to close that gap. Will open a PR referencing this issue once it's ready.

adityaanikam avatar Jul 23 '26 20:07 adityaanikam