Skip to content

Fix get_collection/create_collection Raises docstring (#5492)#7112

Open
adityasingh2400 wants to merge 1 commit into
chroma-core:mainfrom
adityasingh2400:doc-fix-collection-raises-not-found-5492
Open

Fix get_collection/create_collection Raises docstring (#5492)#7112
adityasingh2400 wants to merge 1 commit into
chroma-core:mainfrom
adityasingh2400:doc-fix-collection-raises-not-found-5492

Conversation

@adityasingh2400
Copy link
Copy Markdown

Description of changes

The Raises section on ClientAPI.get_collection says ValueError, but the implementation in chromadb/api/segment.py actually raises NotFoundError. The same mismatch shows up on create_collection, whose Raises lists ValueError for duplicate names while the SysDB / gRPC path raises UniqueConstraintError. The async client and the concrete Client wrapper have the same drift, so callers consulting any of the three files get the wrong exception type to catch.

This PR updates the docstrings in chromadb/api/__init__.py, chromadb/api/async_api.py, and chromadb/api/client.py so the sync and async clients describe the exceptions that are actually raised:

  • get_collection: ValueError becomes NotFoundError.
  • create_collection: the duplicate-name entry becomes UniqueConstraintError; the existing ValueError: If the collection name is invalid. entry is kept since name validation does raise ValueError.
  • Client.get_collection and Client.create_collection: add the missing NotFoundError / UniqueConstraintError entries alongside the existing embedding-function ValueError entry, which is still raised by validate_embedding_function_conflict_on_create / _on_get.

Both NotFoundError and UniqueConstraintError are already exported from chromadb/errors.py, so users can from chromadb.errors import NotFoundError, UniqueConstraintError and catch them today.

Fixes #5492.

This also supersedes the Python portion of #6369, which has been idle for roughly three months and bundles unrelated .github/workflows/_rust-tests.yml GCS credential changes that aren't appropriate for a docs fix.

Test plan

Docstring-only change with no runtime behavior. Verified by reading chromadb/api/segment.py (raise NotFoundError(...) at line 338 for get_collection) and chromadb/db/impl/grpc/client.py (raise UniqueConstraintError() for duplicate-collection paths), and confirming the existing ValueError raises in chromadb/api/client.py come from validate_embedding_function_conflict_on_create / _on_get in chromadb/api/collection_configuration.py.

Documentation Changes

This PR is itself the documentation change. No updates needed in the docs repo.

The Raises section on get_collection said ValueError, but the
implementation actually raises NotFoundError; same shape for
create_collection raising UniqueConstraintError rather than
ValueError. Update the docstrings in chromadb/api/__init__.py,
async_api.py and client.py so async and sync clients line up with
the real exception types.

Fixes chroma-core#5492
@github-actions
Copy link
Copy Markdown

Reviewer Checklist

Please leverage this checklist to ensure your code review is thorough before approving

Testing, Bugs, Errors, Logs, Documentation

  • Can you think of any use case in which the code does not behave as intended? Have they been tested?
  • Can you think of any inputs or external events that could break the code? Is user input validated and safe? Have they been tested?
  • If appropriate, are there adequate property based tests?
  • If appropriate, are there adequate unit tests?
  • Should any logging, debugging, tracing information be added or removed?
  • Are error messages user-friendly?
  • Have all documentation changes needed been made?
  • Have all non-obvious changes been commented?

System Compatibility

  • Are there any potential impacts on other parts of the system or backward compatibility?
  • Does this change intersect with any items on our roadmap, and if so, is there a plan for fitting them together?

Quality

  • Is this code of a unexpectedly high quality (Readability, Modularity, Intuitiveness)

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.

[Bug]: get_collection docstring says ValueError, but implementation raises NotFoundError

1 participant