Skip to content

Python: join the split Weaviate settings error messages into one argument - #14243

Open
ErenAta16 wants to merge 1 commit into
microsoft:mainfrom
ErenAta16:fix-weaviate-multi-arg-exceptions
Open

Python: join the split Weaviate settings error messages into one argument#14243
ErenAta16 wants to merge 1 commit into
microsoft:mainfrom
ErenAta16:fix-weaviate-multi-arg-exceptions

Conversation

@ErenAta16

Copy link
Copy Markdown

Motivation and Context

Four raise sites in connectors/weaviate.py pass two string literals to the exception constructor instead of one concatenated message. Python puts each into args, so str(e) renders the tuple repr:

('Weaviate settings must specify either a ', 'Weaviate Cloud instance, a local Weaviate instance, or the client embedding options.')

instead of

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. 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:

line exception
162 ServiceInvalidExecutionSettingsError — no backend configured
167 ServiceInvalidExecutionSettingsError — more than one backend configured
280 NotImplementedErrorWeaviateCollection.__init__
751 NotImplementedErrorWeaviateStore.__init__

Description

Concatenated the adjacent literals at each site. No control flow or exception types change.

An AST sweep over semantic_kernel/ for raise X("...", "...") — every Raise whose 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_backendsmatch="must specify either a Weaviate Cloud"
  • test_weaviate_collection_init_with_invalid_settings_more_than_one_backendsmatch="only one of the following"
  • the two equivalents in test_weaviate_store.py

Stashing only weaviate.py fails the two "no backends" tests with AssertionError: Regex pattern did not match. The two "more than one" tests pass on both sides — pytest.raises(match=...) searches str(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/weaviate is 23 passed. ruff check and ruff format --check clean.

Notes for the reviewer

Wording is unchanged apart from the join — I kept the original phrasing verbatim rather than rewriting the sentences.

Checklist

…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)
Copilot AI review requested due to automatic review settings July 29, 2026 21:18
@ErenAta16
ErenAta16 requested a review from a team as a code owner July 29, 2026 21:18

@github-actions github-actions 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.

Automated Code Review

Reviewers: 5 | Confidence: 96% | Result: All clear

Reviewed: Correctness, Security Reliability, Test Coverage, Failure Modes, Design Approach


Automated review by ErenAta16's agents

Copilot AI 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.

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 raise sites in python/semantic_kernel/connectors/weaviate.py to 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.

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.

2 participants