feat(python): Add regression coverage for missing optional connector dependencies - #14351
Open
Abhinav Prakash (AbhiPra24) wants to merge 1 commit into
Conversation
…or missing optional connector dependencies - Add actionable extra install messages when importing optional connectors from semantic_kernel.connectors.memory - Update onnx, huggingface, and chroma connector stores with clear install extras on missing dependencies - Add parameterized unit tests in test_optional_connector_dependencies.py covering missing optional dependencies across connectors - Add Oracle vector store re-exports in memory.py Fixes microsoft#14328
Copilot started reviewing on behalf of
Abhinav Prakash (AbhiPra24)
August 31, 2026 10:27
View session
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves the Python connector experience when optional dependencies are missing by surfacing actionable install-extra guidance and adding regression tests to prevent message drift across connectors.
Changes:
- Adds a new parameterized unit test suite covering lazy-import behavior for optional memory connectors plus constructor-time dependency checks for selected connectors.
- Updates
semantic_kernel.connectors.memory(and related stubs) to include Oracle re-exports and to raise more actionable errors on missing optional dependencies. - Updates selected connectors (Chroma, ONNX, HuggingFace) to raise
ServiceInitializationErrormessages that point to the correctsemantic-kernel[...]extra.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| python/tests/unit/connectors/test_optional_connector_dependencies.py | Adds regression tests for lazy imports and for dependency-missing errors during connector construction. |
| python/semantic_kernel/connectors/search.py | Adjusts lazy import mapping for Google search and uses the correct package anchor for relative imports. |
| python/semantic_kernel/connectors/memory.pyi | Adds Oracle connector symbols to the typing stub exports. |
| python/semantic_kernel/connectors/memory.py | Adds Oracle re-exports and maps submodules to install extras for actionable missing-dependency errors. |
| python/semantic_kernel/connectors/memory_stores/chroma/chroma_memory_store.py | Updates deprecated decorator import gating and improves missing-dependency guidance to point to the SK extra. |
| python/semantic_kernel/connectors/ai/onnx/services/onnx_gen_ai_completion_base.py | Raises ServiceInitializationError with install-extra guidance when ONNX optional dependency isn’t installed; minor generator yield cleanup. |
| python/semantic_kernel/connectors/ai/hugging_face/hf_prompt_execution_settings.py | Makes transformers import detection robust and raises ServiceInitializationError with install-extra guidance when missing. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+73
to
+80
| except (ModuleNotFoundError, ImportError) as ex: | ||
| extra = _EXTRA_MAP.get(submod_name) | ||
| if extra: | ||
| raise ModuleNotFoundError( | ||
| f"Could not import {name} from {submod_name}. " | ||
| f"Please install the optional dependency with `pip install semantic-kernel[{extra}]`." | ||
| ) from ex | ||
| raise |
Comment on lines
+72
to
+80
| def mock_import_module(name: str, package: str | None = None): | ||
| if name == submod_name: | ||
| raise ModuleNotFoundError(f"No module named 'fake_{expected_extra}'", name=f"fake_{expected_extra}") | ||
| return importlib.__import__(name) | ||
|
|
||
| with ( | ||
| patch("importlib.import_module", side_effect=mock_import_module), | ||
| pytest.raises(ModuleNotFoundError) as exc_info, | ||
| ): |
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.
Description
This PR addresses Issue #14328 by adding comprehensive regression coverage and actionable error handling when importing or constructing connectors with missing optional dependencies.
Changes
semantic_kernel.connectors.memorylazy module loading to catch missing dependency errors and raise actionableModuleNotFoundErrorindicating the exact extra to install (e.g.pip install semantic-kernel[<extra>]).semantic_kernel.connectors.memoryandmemory.pyi.ServiceInitializationErrormessages citing the specific install extras when optional dependencies are missing.python/tests/unit/connectors/test_optional_connector_dependencies.pycovering lazy imports across all optional connectors (Chroma, Qdrant, Weaviate, Pinecone, Postgres, Redis, Mongo, Faiss, Oracle, SQL Server, Azure AI Search, Cosmos DB) as well as instantiation checks.Fixes #14328