Python: join the split Weaviate settings error messages into one argument - #14243
Open
ErenAta16 wants to merge 1 commit into
Open
Python: join the split Weaviate settings error messages into one argument#14243ErenAta16 wants to merge 1 commit into
ErenAta16 wants to merge 1 commit into
Conversation
…ment
Four raises in connectors/weaviate.py pass two string literals to the
exception constructor instead of one concatenated message, so the second
becomes a second element of args and str(e) renders the tuple repr:
('Weaviate settings must specify either a ', 'Weaviate Cloud instance, a
local Weaviate instance, or the client embedding options.')
Anything that logs or displays the exception shows quotes, a comma and
parentheses around the sentence. The message is the only thing telling a user
which of the three mutually exclusive Weaviate backends to configure, and it
reaches them mangled.
Concatenate the literals at each site: two ServiceInvalidExecutionSettingsError
raises in the settings validator and two NotImplementedError raises in the
collection and store constructors.
Tightened the four existing weaviate init tests with match= so the message
shape is pinned rather than only the exception type. An AST sweep over
semantic_kernel/ finds no remaining multi-argument string raises.
Closes # (no open issue)
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes Python exception message rendering for the Weaviate connector by ensuring each raise site passes a single concatenated string (rather than multiple string literals that become a tuple in Exception.args). It also tightens unit tests to assert the intended error-message shape via pytest.raises(..., match=...).
Changes:
- Concatenate adjacent string literals at four
raisesites inpython/semantic_kernel/connectors/weaviate.pyto produce a single, clean exception message. - Update existing Weaviate unit tests to assert message content using
match=...for the relevant invalid-settings cases.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| python/semantic_kernel/connectors/weaviate.py | Joins split exception message literals so str(e) is a readable sentence rather than a tuple repr. |
| python/tests/unit/connectors/memory/weaviate/test_weaviate_collection.py | Adds match= assertions to pin the expected exception message for invalid settings. |
| python/tests/unit/connectors/memory/weaviate/test_weaviate_store.py | Adds match= assertions to pin the expected exception message for invalid settings. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation and Context
Four
raisesites inconnectors/weaviate.pypass two string literals to the exception constructor instead of one concatenated message. Python puts each intoargs, sostr(e)renders the tuple repr:instead of
Anything that logs or displays the exception shows quotes, a comma and parentheses around the sentence. That message is the only thing telling a user which of the three mutually exclusive Weaviate backends to configure, so it's the one place the wording matters.
Sites:
ServiceInvalidExecutionSettingsError— no backend configuredServiceInvalidExecutionSettingsError— more than one backend configuredNotImplementedError—WeaviateCollection.__init__NotImplementedError—WeaviateStore.__init__Description
Concatenated the adjacent literals at each site. No control flow or exception types change.
An AST sweep over
semantic_kernel/forraise X("...", "...")— everyRaisewhose call has two or more string-constant/f-string arguments — reports 4 before this change and 0 after, so these were the only occurrences.How did you test it?
The four existing weaviate init tests already asserted the exception type; I added
match=so the message shape is pinned too:test_weaviate_collection_init_with_invalid_settings_no_backends→match="must specify either a Weaviate Cloud"test_weaviate_collection_init_with_invalid_settings_more_than_one_backends→match="only one of the following"test_weaviate_store.pyStashing only
weaviate.pyfails the two "no backends" tests withAssertionError: Regex pattern did not match.The two "more than one" tests pass on both sides —pytest.raises(match=...)searchesstr(e), and"only one of the following: "is the first tuple element, so the substring is still present in the mangled repr. They're in the diff as controls, not as evidence.With the change,
tests/unit/connectors/memory/weaviateis 23 passed.ruff checkandruff format --checkclean.Notes for the reviewer
Wording is unchanged apart from the join — I kept the original phrasing verbatim rather than rewriting the sentences.
Checklist