Repository navigation
Python: Allow injected Azure Search clients alongside connection arguments - #10309
Dhruv Shaswat (Dhruv-Sh-git) wants to merge 1 commit into
Conversation
…xist with connection args
Muhammad Abdullah Butt (1AbdullahButt)
left a comment
There was a problem hiding this comment.
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.
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
Impact
Users can now reuse existing Azure Search clients without having to remove additional connection arguments.
Review Focus
Related Issue
Fixes #9956
AI Assistance