Skip to content

fix: Chroma - guard empty filter conditions and increase unit tests coverage - #3797

Draft
julian-risch wants to merge 1 commit into
mainfrom
test/chroma-unit-coverage
Draft

fix: Chroma - guard empty filter conditions and increase unit tests coverage#3797
julian-risch wants to merge 1 commit into
mainfrom
test/chroma-unit-coverage

Conversation

@julian-risch

Copy link
Copy Markdown
Member

Related Issues

Proposed Changes:

  • _create_where_document_filter indexed value[0] unconditionally, so a logical filter with an empty conditions list raised IndexError instead of a ChromaDocumentStoreFilterError. Guard it.
  • Add unit tests for filters.py, which previously had only four error-path tests, and for the @staticmethods that had none: _prepare_get_kwargs, _prepare_query_kwargs, _build_fields_info, _prepare_metadata_update, _apply_duplicate_policy.
  • Cover the collection-backed methods and their async twins by injecting a mock collection, which both _ensure_initialized paths short-circuit on, so no Chroma client is created.

How did you test it?

Notes for the reviewer

Checklist

  • I have read the contributors guidelines and the code of conduct
  • I have updated the related issue with new insights and changes — n/a
  • I added unit tests and updated the docstrings
  • I've used one of the conventional commit types for my PR title: fix:, feat:, build:, chore:, ci:, docs:, style:, refactor:, perf:, test:.

…overage

_create_where_document_filter indexed value[0] unconditionally, so a
logical filter with an empty conditions list raised IndexError instead of
a ChromaDocumentStoreFilterError. With the guard, the empty clause falls
through to Chroma's own validation and surfaces as a filter error.

On top of that, cover the code paths that were only reachable through the
integration-marked tests, which the unit coverage badge excludes:

filters.py, which had only four error-path tests before:
- every comparison operator's mapping to its Chroma equivalent, the
  meta. prefix stripping, and all four malformed-condition errors
- _parse_logical_condition for AND, OR and nesting
- _create_where_document_filter, including how content conditions under a
  logical operator are combined
- _convert_filters splitting a filter into ids, where and where_document

document_store.py statics that had no test at all: _prepare_get_kwargs,
_prepare_query_kwargs, _build_fields_info, _prepare_metadata_update and
_apply_duplicate_policy, plus the remaining _convert_document_to_chroma
branches for list metadata, unsupported types and blobs.

The collection-backed methods are driven by injecting a mock collection
onto the store: _ensure_initialized and _ensure_initialized_async both
short-circuit once a collection is set, so no Chroma client is created.
These assert the kwargs handed to the collection rather than round-tripped
data, and cover write/delete/update by filter, the metadata aggregation
family, search, the DocumentStoreError wrapping, and every async twin.

Client construction is deliberately left to the integration tests.

Unit coverage: 47% -> 95%.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added integration:chroma type:documentation Improvements or additions to documentation labels Aug 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Coverage report (chroma)

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  integrations/chroma/src/haystack_integrations/document_stores/chroma
  document_store.py
  filters.py
Project Total  

This report was generated by python-coverage-comment-action

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

Labels

integration:chroma type:documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant