Skip to content

[BUG] Raise Error when can't deserialize configuration json from server #4471

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jairad26
Copy link
Contributor

@jairad26 jairad26 commented May 7, 2025

Description of changes

This PR fixes a bug where it warns users if the configuration is not deserializable rather than raising an error, giving the users an empty config

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?

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

This stack of pull requests is managed by Graphite. Learn more about stacking.

@jairad26 jairad26 marked this pull request as ready for review May 7, 2025 01:14
@jairad26 jairad26 force-pushed the jai/fix-list-collections branch from c11b7ad to cd63d71 Compare May 7, 2025 16:33
Copy link
Contributor

propel-code-bot bot commented May 7, 2025

This PR modifies error handling in configuration deserialization by raising ValueError instead of using warnings and empty objects. It changes how undeserializable configurations are handled, returning None values for spann and hnsw configurations instead of empty objects.

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

@jairad26 jairad26 force-pushed the jai/fix-list-collections branch 3 times, most recently from b40998d to af51006 Compare May 7, 2025 19:54
Comment on lines 185 to 174
configuration = CollectionConfiguration(
hnsw=None,
spann=None,
embedding_function=None,
)
Copy link
Contributor

Choose a reason for hiding this comment

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

[DataTypeCheck]

Now the fallback value for configuration in from_json() constructs CollectionConfiguration(hnsw=None, spann=None, embedding_function=None). Confirm that this matches the expected constructor signature and field types. Add appropriate type annotations to CollectionConfiguration to clarify that None is valid for these fields, or provide documentation about acceptable values.

@jairad26 jairad26 force-pushed the jai/fix-list-collections branch from af51006 to 318d249 Compare May 7, 2025 21:54
@@ -8,16 +8,13 @@
from uuid import UUID
from enum import Enum
from pydantic import BaseModel
import warnings

Copy link
Contributor

Choose a reason for hiding this comment

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

[CriticalError]

The warnings module is used in this file now (see usage in chromadb/api/collection_configuration.py), but it is not imported. Add the import at the top of the file to prevent runtime errors.

Comment on lines 88 to 92
warnings.warn(
f"Embedding function {ef_config['name']} not found. Add @register_embedding_function decorator to the class definition.",
stacklevel=2,
)
ef = None
Copy link
Contributor

Choose a reason for hiding this comment

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

[BestPractice]

Changing from ValueError to warnings.warn and ef = None when an embedding function is not found might mask critical configuration errors. If an embedding function is specified in the configuration but cannot be located, it typically indicates a misconfiguration that should prevent the system from proceeding as if everything is normal. This could lead to a collection being created or used without the intended embedding capabilities, with the issue only becoming apparent later. Raising an error ensures such issues are addressed immediately. This approach is also more consistent with the stricter error handling for configuration loading adopted elsewhere in these changes (e.g., in chromadb/types.py).

Consider restoring the behavior of raising an error:

Suggested change
warnings.warn(
f"Embedding function {ef_config['name']} not found. Add @register_embedding_function decorator to the class definition.",
stacklevel=2,
)
ef = None
raise ValueError(
f"Embedding function {ef_config['name']} not found. Add @register_embedding_function decorator to the class definition."
)

Committable suggestion

Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

@jairad26 jairad26 force-pushed the jai/fix-list-collections branch from 318d249 to 7bb55b9 Compare May 7, 2025 22:02
Comment on lines 146 to +149
try:
return load_collection_configuration_from_json(self.configuration_json)
except Exception as e:
warnings.warn(
f"Server does not respond with configuration_json. Please update server: {e}",
DeprecationWarning,
stacklevel=2,
)
return CollectionConfiguration(
hnsw=HNSWConfiguration(),
spann=SpannConfiguration(),
embedding_function=None,
raise ValueError(
Copy link
Contributor

Choose a reason for hiding this comment

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

[CriticalError]

Instead of returning a default configuration on deserialization error, now code raises ValueError. Ensure that all consumers of this method are prepared to handle this exception appropriately. If unhandled, it may lead to crashes during deserialization.

Comment on lines 168 to 169
try:
configuration_json = json_map.get("configuration_json", None)
Copy link
Contributor

Choose a reason for hiding this comment

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

[DataTypeCheck]

Calls to load_collection_configuration_from_json may now receive None for configuration_json. Before calling the loader, consider explicitly validating the presence of configuration_json to provide a clearer error message.

@jairad26 jairad26 changed the title [BUG] Replace empty config objects with None during deserializing [BUG] Raise Error when can't deserialize configuration json from server May 12, 2025
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.

1 participant