Repository navigation
Python: Prefer injected DocumentDB clients over connection settings - #9999
Yufeng He (he-yufeng) wants to merge 7 commits into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Missing-selector errors reference a nonexistent constructor argument, and precedence tests leave registered-model collection names untested against conflicting environment settings.
2 open issues
What changed in this PR
This PR addresses #9954 by making the Python DocumentDB connector prefer caller-injected PyMongo objects over connection settings while preserving caller ownership.
Changes:
- Separates resource-selector resolution from client-construction settings.
- Adds environment fallback for unresolved selectors, with model-defined collection names taking precedence.
- Documents injection behavior and adds regression tests for precedence, validation, and cleanup.
| File | Description |
|---|---|
python/packages/azure-documentdb/tests/azure_documentdb/test_settings.py |
Adds injection, selector, name-mismatch, and ownership regression coverage. |
python/packages/azure-documentdb/README.md |
Explains injected-object precedence and selector fallback. |
python/packages/azure-documentdb/agent_framework_azure_documentdb/_vector_store.py |
Updates injection handling, isolates selector settings, and documents constructor behavior. |
Review effort: Balanced
…b-injected-client-precedence
…b-injected-client-precedence
|
The two hosted coverage failures are outside this connector diff. On The same ordered control passes on the current head of #9250. I am keeping this PR scoped to DocumentDB rather than adding an unrelated core patch, and will merge main and recheck the hosted suite after that session restoration work lands. On the current head, the complete DocumentDB connector suite passes with 130 passed and 1 skipped. |
…b-injected-client-precedence
|
Merged current main in The coverage failure came from test state leaking across the aggregate worker: On the merged head, DocumentDB is 130 passed and 1 skipped, while the session and function-invocation files are 675 passed and 1 skipped. Syntax, strict Pyright, and the pre-commit hooks pass. The PR diff remains limited to the DocumentDB connector, its tests, and the package README. |

Motivation & Context
AzureDocumentDBStoreandAzureDocumentDBCollectionreject caller-supplied PyMongo clients, databases, and collections whenever redundant connection settings are present. They also require an explicit database name for an account-level injected client instead of using the existing environment selector. This prevents configuration layers from injecting a fully configured object while still forwarding unrelated construction settings.Fixes #9954, which is labelled
ready-for-implementationand defines the injection, selector, and ownership acceptance cases. No competing open PR exists for this issue.Description & Review Guide
.envfiles, and ambient connection settings. Account clients resolve a missing database selector fromAZURE_DOCUMENTDB_DATABASE_NAME. Collections created from an injected client or database resolve a missing collection selector from an explicit argument, the registered model definition, thenAZURE_DOCUMENTDB_COLLECTION_NAME. Resource settings are loaded separately, so connection parsing and validation cannot leak back into these paths.database_nameorcollection_nameconstructor argument. On current headabc573b49c, the complete connector suite is 130 passed, 1 skipped; mypy and zuban report no issues in the four test source files, Pyright reports zero source errors, and Ruff passes.Related Issue
Fixes #9954
AI Assistance
AI assistance details: implementation, tests, documentation, and this PR description. The author reviewed the final diff, ran the base-to-fixed regression controls and connector suite, and checked Ruff, Pyright, and repository hooks locally.
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix); a workflow keeps the label and title prefix in sync automatically.