Skip to content

feat(python): Add regression coverage for missing optional connector dependencies - #14351

Open
Abhinav Prakash (AbhiPra24) wants to merge 1 commit into
microsoft:mainfrom
AbhiPra24:feat/python-connector-optional-dependency-coverage
Open

feat(python): Add regression coverage for missing optional connector dependencies#14351
Abhinav Prakash (AbhiPra24) wants to merge 1 commit into
microsoft:mainfrom
AbhiPra24:feat/python-connector-optional-dependency-coverage

Conversation

@AbhiPra24

Copy link
Copy Markdown

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

  • Updated semantic_kernel.connectors.memory lazy module loading to catch missing dependency errors and raise actionable ModuleNotFoundError indicating the exact extra to install (e.g. pip install semantic-kernel[<extra>]).
  • Added Oracle vector store re-exports to semantic_kernel.connectors.memory and memory.pyi.
  • Updated ONNX, HuggingFace, and Chroma connector classes to produce clear ServiceInitializationError messages citing the specific install extras when optional dependencies are missing.
  • Added comprehensive parameterized regression tests in python/tests/unit/connectors/test_optional_connector_dependencies.py covering 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

…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 AI lite review requested due to automatic review settings August 31, 2026 10:25
@AbhiPra24
Abhinav Prakash (AbhiPra24) requested a review from a team as a code owner August 31, 2026 10:25

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 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 ServiceInitializationError messages that point to the correct semantic-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,
):
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.

Add regression coverage for missing optional connector dependencies

2 participants