Skip to content

fix: copy include list before in-place mutation in get/query (#5857) - #7472

Open
rkfshakti wants to merge 1 commit into
chroma-core:mainfrom
rkfshakti:fix/include-param-in-place-mutation
Open

fix: copy include list before in-place mutation in get/query (#5857)#7472
rkfshakti wants to merge 1 commit into
chroma-core:mainfrom
rkfshakti:fix/include-param-in-place-mutation

Conversation

@rkfshakti

Copy link
Copy Markdown

Problem

The include parameter passed to collection.get() and collection.query() is mutated in-place without copying, causing corruption when the same list object is reused across multiple calls.

CollectionCommon.py lines 282 and 346:

request_include = include  # No copy — just a reference
if "data" in include and "uris" not in include:
    request_include.append("uris")  # Mutates the caller's list

Impact

  • Shared list objects get permanently modified ("uris" appended)
  • Mutations accumulate across function calls
  • Can trigger validation errors in newer versions with stricter type checking

Reproduction

my_include = ["embeddings", "documents"]
collection.query(query_texts=["test1"], include=my_include)
# my_include is now ["embeddings", "documents", "uris"] — mutated!
collection.query(query_texts=["test2"], include=my_include)
# Uses corrupted list from previous call

Fix

Copy the list before any in-place modification:

request_include = list(include) if include else []

Applied to both _validate_and_prepare_get_request and _validate_and_prepare_query_request.

Tests

Added two regression tests:

  • test_include_not_mutated_by_query — verifies the include list is not mutated across two query() calls
  • test_include_not_mutated_by_get — verifies the include list is not mutated across two get() calls

Fixes #5857

…core#5857)

The _validate_and_prepare_get_request and _validate_and_prepare_query_request
methods assigned request_include = include without copying, then mutated it
with .append('uris'). This corrupted the caller's list object, causing
validation errors on subsequent calls that reused the same list.

Fix: use list(include) to create a copy before any mutation.

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@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)

@rkfshakti

Copy link
Copy Markdown
Author

Hi maintainers — gentle bump on this fix for #5857. Copies the include list before in-place mutation in get()/query() to prevent list corruption across calls. Ready for review. Thanks!

@rkfshakti

Copy link
Copy Markdown
Author

Hi maintainers — circling back on this fix for #5857. Curious if the copy-before-mutation approach for the include list looks right, or if there's a different pattern you'd prefer. Happy to rework. Keen to contribute! Thanks.

@rkfshakti

Copy link
Copy Markdown
Author

Friendly ping — this PR has been open for a couple of days with CI passing. Would appreciate a review when time allows.

@rkfshakti

Copy link
Copy Markdown
Author

Hi maintainers — following up again on this fix for #5857. Copies the include list before in-place mutation in get/query to prevent side effects. CI is green. Would appreciate a review when time allows. Thanks!

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]: Query - In-place mutation of include parameter causes corruption across calls

1 participant