Skip to content

fix(collections): re-raise non-404 errors from async Collection.exists() (#2100) - #2112

Open
Anai-Guo wants to merge 1 commit into
weaviate:mainfrom
Anai-Guo:fix/async-collection-exists-reraise
Open

fix(collections): re-raise non-404 errors from async Collection.exists() (#2100)#2112
Anai-Guo wants to merge 1 commit into
weaviate:mainfrom
Anai-Guo:fix/async-collection-exists-reraise

Conversation

@Anai-Guo

Copy link
Copy Markdown

Fixes #2100

Problem

CollectionAsync.exists() still had a bare catch-all:

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

so a connection error, auth failure or timeout is indistinguishable from "collection not found". The common guard

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

therefore tries to re-create the collection whenever the server is merely unreachable, masking the outage.

#1799 reported exactly this. #1950 fixed the sync path in weaviate/collections/collection/sync.py but the async counterpart was never updated.

Change

Mirror the sync implementation exactly — return False on 404, re-raise everything else:

except UnexpectedStatusCodeError as e:
    if e.status_code == 404:
        return False
    raise e

Test

Adds test_async_collection_exists to mock_tests/test_collection.py, following the existing test_collection_exists shape and the use_async_with_local pattern already used in mock_tests/test_auth.py. It asserts both branches: 404 → False, 500 → UnexpectedStatusCodeError with status_code == 500.

Verified locally against the mock server:

new test full mock_tests/test_collection.py
main (ae327ca), test only FAILED — DID NOT RAISE UnexpectedStatusCodeError
with this fix passed 21 passed

ruff / ruff format (pinned v0.14.7) and flake8 are clean on both touched files.

🤖 Generated with Claude Code

The async `Collection.exists()` still had a bare `except Exception: return
False`, so a connection error, auth failure or timeout was indistinguishable
from "collection not found". PR weaviate#1950 fixed this for the sync path only.

Mirror the sync implementation: return False on 404 and re-raise anything
else. Adds a mock test covering both branches on the async client.

Fixes weaviate#2100

@orca-security-eu orca-security-eu Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Orca Security Scan Summary

Status Check Issues by priority
Passed Passed Infrastructure as Code high 0   medium 0   low 0   info 0 View in Orca
Passed Passed SAST high 0   medium 0   low 0   info 0 View in Orca
Passed Passed Secrets high 0   medium 0   low 0   info 0 View in Orca
Passed Passed Vulnerabilities high 0   medium 0   low 0   info 0 View in Orca

@weaviate-git-bot

Copy link
Copy Markdown

To avoid any confusion in the future about your contribution to Weaviate, we work with a Contributor License Agreement. If you agree, you can simply add a comment to this PR that you agree with the CLA so that we can merge.

beep boop - the Weaviate bot 👋🤖

PS:
Are you already a member of the Weaviate Forum?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants