Skip to content

fix: copy include list before mutating in get/query#7109

Open
rmotgi1227 wants to merge 1 commit into
chroma-core:mainfrom
rmotgi1227:fix/include-list-mutation
Open

fix: copy include list before mutating in get/query#7109
rmotgi1227 wants to merge 1 commit into
chroma-core:mainfrom
rmotgi1227:fix/include-list-mutation

Conversation

@rmotgi1227
Copy link
Copy Markdown

If you pass the same include list to multiple collection.query() or collection.get() calls, the list gets "uris" appended to it on the first call and stays mutated for all subsequent calls. Depending on how many times you call it you can end up with duplicate entries which then fails validation.

Root cause: _validate_and_prepare_get_request and _validate_and_prepare_query_request both do request_include = include (a reference, not a copy) before calling request_include.append("uris").

Fix is request_include = list(include) in both places — one line each.

Fixes #5857

_validate_and_prepare_get_request and _validate_and_prepare_query_request
both assigned request_include = include (a reference) and then called
request_include.append('uris'). This mutated the caller's list in place,
so passing the same include list to multiple calls would accumulate 'uris'
entries and cause unexpected behaviour on repeated calls.

Fix: request_include = list(include) makes a shallow copy so the original
is never modified.

Fixes chroma-core#5857
@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]: Query - In-place mutation of include parameter causes corruption across calls

1 participant