Skip to content

Python: Allow injected Azure Search clients alongside connection arguments - #10309

Open
Dhruv Shaswat (Dhruv-Sh-git) wants to merge 1 commit into
microsoft:mainfrom
Dhruv-Sh-git:fix/issue-9956-clean
Open

Dhruv Shaswat (Dhruv-Sh-git) wants to merge 1 commit into
microsoft:mainfrom
Dhruv-Sh-git:fix/issue-9956-clean

Conversation

@Dhruv-Sh-git

Copy link
Copy Markdown
Contributor

Motivation & Context

Passing an existing Azure Search client alongside endpoint or credential arguments currently raises an unnecessary ValueError. When a client is explicitly injected, it should take precedence over these additional connection settings.

Description & Changes

  • Removed the validation that rejected injected search_client or index_client instances when connection arguments were also provided.
  • Updated the constructor to allow these arguments to coexist.
  • Preserved the injected client's precedence.

Impact

Users can now reuse existing Azure Search clients without having to remove additional connection arguments.

Review Focus

  • Verify injected client precedence.
  • Check both search_client and index_client behavior.
  • Ensure normal client initialization remains unaffected.

Related Issue

Fixes #9956

AI Assistance

  • AI assistance was used during implementation. I reviewed and verified the changes and take responsibility for the contribution.

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@agent-framework-automation agent-framework-automation Bot added the python Usage: [Issues, PRs], Target: Python label Nov 12, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This covers only half of #9956, and the existing tests still expect the old error.

1. AzureAISearchStore still raises. The PR removes the check in AzureAISearchCollection.__init__, but the same check in AzureAISearchStore.__init__ is untouched (_vector_store.py:942-948 at this head). So the issue's own repro, AzureAISearchStore(index_client=index_client, endpoint="https://ignored.search.windows.net"), still raises Injected clients cannot be combined ....

2. test_injected_clients_reject_explicit_settings_before_resolution will fail. That test (tests/test_vector_store.py:1225-1258) is parametrized over store, collection-index, collection-search and collection-both, crossed with five overrides, and it wraps the constructor in pytest.raises(ValueError, match="Injected clients cannot be combined"). With this change, the 15 collection cases construct successfully, so pytest.raises fails. I worked that out from the code. I didn't run the test.

3. The ownership half of the issue isn't addressed. #9956 also asks that managed_client=True no longer transfer ownership of an injected client. The elif index_client is not None and managed_client / elif managed_client branches that append injected clients to _owned_clients are still there. The docstrings at :292-294 and :932 also still say "cannot be combined" and "mutually exclusive".

4. Code style. The four added comment lines describe the change history ("Previously we raised...", "No action needed"). They would read better as a one-line note in the docstring, or simply left out.

For the maintainers: on #9956, eavanvalkenburg asked to "use ... the existing #10001 implementation; do not start a parallel PR". #10001 changes both constructors, the ownership branches, the docs and the tests, so this PR is likely a duplicate of it.

git merge-tree against main is clean.

Reviewed with help from Claude Code.

This branch was successfully deployed

1 active deployment
github-app-auth — 41ba94d0 Deployed Nov 12, 2026 by Dhruv-Sh-git via team_check #9383
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: Azure AI Search injected clients do not take precedence over connection settings

3 participants