Skip to content

[ENH] Disallow empty string ids during add #4488

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 8, 2025
Merged

Conversation

jairad26
Copy link
Contributor

@jairad26 jairad26 commented May 7, 2025

Description of changes

This PR disallows setting an empty string for an ID
#4346

Test plan

How are these changes tested?

  • Tests pass locally with pytest for python, yarn test for js, cargo test for rust

Documentation Changes

Are all docstrings for user-facing APIs updated if required? Do we need to make documentation changes in the docs section?


This PR adds validation to prevent empty string IDs during the record addition process. It modifies the Rust codebase to reject IDs with zero characters by adding a new error type and appropriate validation check, addressing issue #4346.

Key Changes:
• Added a new EmptyId error type to the ToRecordsError enum
• Added validation to check for empty IDs in the to_records function
• Added comprehensive test cases to verify the validation behavior

Affected Areas:
• rust/frontend/src/impls/utils.rs

This summary was automatically generated by @propel-code-bot

Copy link

github-actions bot commented May 7, 2025

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)

Copy link
Contributor Author

jairad26 commented May 7, 2025

@jairad26 jairad26 marked this pull request as ready for review May 7, 2025 23:33
Copy link
Contributor

propel-code-bot bot commented May 7, 2025

Disallow Empty String IDs During Record Addition

This PR adds validation to the Rust codebase to prevent empty string IDs (zero-length) when adding records to Chroma. It introduces a new error type EmptyId and adds a validation check in the to_records function to reject IDs without any characters.

Key Changes:
• Added EmptyId error type to ToRecordsError enum with appropriate error message
• Added validation check to reject empty string IDs in the to_records function
• Added comprehensive test cases to verify both error and success scenarios

Affected Areas:
• rust/frontend/src/impls/utils.rs

This summary was automatically generated by @propel-code-bot

Vec<(String, chroma_types::UpdateMetadataValue)>,
>(ids, Some(embeddings), None, None, None, Operation::Add);
assert!(matches!(result, Err(ToRecordsError::EmptyId)));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

[TestCoverage]

You should add a test case for IDs containing valid non-empty values (including whitespace or unusual Unicode), to ensure is_empty() is the correct check and not overly restrictive. This will prevent regressions if the ID requirements change.

Comment on lines 106 to 109
let result = super::to_records::<
chroma_types::UpdateMetadataValue,
Vec<(String, chroma_types::UpdateMetadataValue)>,
>(ids, Some(embeddings), None, None, None, Operation::Add);
Copy link
Contributor

Choose a reason for hiding this comment

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

[BestPractice]

Since use super::*; is already present (line 100), the super:: prefix in super::to_records is redundant. You can call to_records directly.

@jairad26 jairad26 force-pushed the jai/disallow-empty-id branch from 250973a to 228f284 Compare May 8, 2025 18:25
@jairad26 jairad26 force-pushed the jai/disallow-empty-id branch from 228f284 to 896f24f Compare May 8, 2025 18:43
@jairad26 jairad26 merged commit 3241753 into main May 8, 2025
71 checks passed
@@ -47,6 +49,9 @@ pub(crate) fn to_records<
let mut records = Vec::with_capacity(len);

for id in ids {
if id.is_empty() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This seems inconsistent with the rest of our code where we use #[validate]

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.

3 participants