Fix health check query not executed#4927
Open
JC-wk wants to merge 3 commits into
Open
Conversation
* Health check can falsely return OK even if Cosmos is down or inaccessible. ([microsoft#4926](microsoft#4926))
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request fixes the Cosmos DB health check so it actually executes a query (preventing false “OK” results when Cosmos is unreachable), and updates the API’s unit tests, changelog, and version accordingly.
Changes:
- Execute the Cosmos query by iterating the async result (
async for ... break) withmax_item_count=1. - Add unit tests covering Cosmos HTTP errors and query-time request errors.
- Update
CHANGELOG.mdand bumpapi_appversion.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
api_app/services/health_checker.py |
Forces Cosmos query execution during health check and maps CosmosHttpResponseError to “not accessible”. |
api_app/tests_ma/test_services/test_health_checker.py |
Adds tests for Cosmos HTTP/query-time failures (but one existing “responding” test needs updating to reflect the new iteration behavior). |
CHANGELOG.md |
Documents the bug fix under Unreleased “BUG FIXES”. |
api_app/_version.py |
Bumps API version from 0.25.16 to 0.25.17. |
Unit Test Results675 tests 675 ✅ 7s ⏱️ Results for commit 8541ce2. ♻️ This comment has been updated with latest results. |
added 2 commits
June 8, 2026 10:52
api.dependencies.database.Database.
get_container_proxy instead of azure.cosmos.aio.ContainerProxy.query_items .
• Configured the return value of get_container_proxy_mock to be a mock container whose
query_items function returns a real async iterator: AsyncIterator([{"id": "item"}]) .
• Verified that all unit tests pass, and successfully ran the entire test suite (all 675 tests
passed).
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.
Resolves #4926
What is being addressed
The existing code
container.query_items("SELECT TOP 1 * FROM c")does not actually execute the query so the health check can falsely return OK even if Cosmos is down or inaccessible.How is this addressed