Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a critical bug in the Cosmos DB SDK's location routing logic where unavailable regional endpoints were being dropped from the routing list instead of being appended to the end as fallback options.
Changes:
- Modified the condition in
get_preferred_regional_routing_contextsto always append unavailable endpoints to the routing list (changed fromif not regional_endpoints and unavailable_endpoints:toif unavailable_endpoints:) - Added comprehensive tests to verify that unavailable endpoints are retained in the routing list and properly ordered (healthy endpoints first, unavailable at the end)
- Updated comments to clarify the purpose of keeping unavailable endpoints as last-resort fallback options
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| sdk/cosmos/azure-cosmos/azure/cosmos/_location_cache.py | Fixed the bug by changing the condition to always append unavailable endpoints to the routing list, and updated the comment to explain the rationale |
| sdk/cosmos/azure-cosmos/tests/test_location_cache.py | Added two comprehensive tests: one verifying that unavailable endpoints are not dropped when using excluded_locations, and another verifying proper ordering of healthy vs unavailable endpoints |
Comment on lines
+527
to
532
| # Always append unavailable endpoints to the end of the list so they can be | ||
| # used as a last resort. This ensures that when all healthy endpoints are filtered | ||
| # out (e.g., by excluded_locations), the SDK can still fall back to unavailable | ||
| # regional endpoints rather than the global endpoint. | ||
| if unavailable_endpoints: | ||
| regional_endpoints.extend(unavailable_endpoints) |
There was a problem hiding this comment.
This bug fix should be documented in the CHANGELOG.md file. Consider adding an entry under a new unreleased version section (e.g., "### 4.15.1 (Unreleased)") with a "#### Bugs Fixed" subsection describing how unavailable endpoints are now properly retained in the routing list as fallback options instead of being dropped entirely.
Member
Author
|
/azp run python - cosmos - tests |
|
Azure Pipelines successfully started running 1 pipeline(s). |
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.
we currently have a bug in the SDK where unavailable endpoints are dropped from the list instead of being appended to the end.
current (buggy) code:
if not regional_endpoints and unavailable_endpoints:
regional_endpoints.extend(unavailable_endpoints)
only adds unavailable endpoints back if ALL are unavailable.
expected(correct) code:
if unavailable_endpoints:
regional_endpoints.extend(unavailable_endpoints)