Skip to content

[Cosmos] Port None handling fix for database_account parameter#44987

Merged
simorenoh merged 4 commits intomainfrom
copilot/port-none-handling-changes
Feb 5, 2026
Merged

[Cosmos] Port None handling fix for database_account parameter#44987
simorenoh merged 4 commits intomainfrom
copilot/port-none-handling-changes

Conversation

Copy link
Contributor

Copilot AI commented Feb 3, 2026

Ports None handling changes from PR #44939 (hotfix branch) to main. The original fix prevents AttributeError: 'NoneType' object has no attribute '_WritableLocations' when force_refresh_on_startup(None) is called.

Core Changes

Sync endpoint manager (_global_endpoint_manager.py):

  • Added explicit None check before using database_account in startup path
  • Fetches database account when None is passed instead of attempting to use it

Async endpoint manager (_global_endpoint_manager_async.py):

  • Modified condition from if not self._aenter_used: to if not self._aenter_used or database_account is None:
  • Ensures database account is fetched when None even if _aenter_used=True (the optimization flag introduced in 4.14.2)

Test Changes

  • Added 2 sync tests in test_health_check.py: None handling and optimization validation
  • Added 3 async tests in test_health_check_async.py: None handling, optimization validation, and _aenter_used flag interaction
  • Fixed test_multimaster.py: Changed from index-based header assertions to count-based validation (more robust against call order changes)
  • Updated async health check test to use polling instead of fixed sleep

Example of Fixed Scenario

# Previously crashed with AttributeError
gem = client.client_connection._global_endpoint_manager
gem.force_refresh_on_startup(None)  # Now handles None gracefully

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • scanning-api.github.com
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node /home/REDACTED/work/_temp/ghcca-node/node/bin/node --enable-source-maps /home/REDACTED/work/_temp/copilot-developer-action-main/dist/index.js (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>[Cosmos] port new None handling changes to main branch</issue_title>
<issue_description>Some changes were made to a feature branch that were merged in and released separately from our main branch. The changes are present here: #44939

The task at hand is to port over all of the changes in that pull request so that the feature branch and main branches both have those changes.</issue_description>

<agent_instructions>Take a look at the feature branch pull request that was linked and port those changes exactly over to the main branch of the repo. If you can't do it for some reason, make sure to outline what was missing or what could not be done in your comments.</agent_instructions>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: simorenoh <30335873+simorenoh@users.noreply.github.com>
Copilot AI changed the title [WIP] Port new None handling changes to main branch [Cosmos] Port None handling fix for database_account parameter Feb 3, 2026
Copilot AI requested a review from simorenoh February 3, 2026 22:36
@simorenoh simorenoh marked this pull request as ready for review February 4, 2026 17:50
@simorenoh simorenoh requested a review from a team as a code owner February 4, 2026 17:50
Copilot AI review requested due to automatic review settings February 4, 2026 17:50
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Ports the force_refresh_on_startup(None) None-handling hotfix from a released branch into main to prevent crashes during startup/region discovery, and adds targeted regression tests.

Changes:

  • Add explicit database_account is None handling in sync and async global endpoint managers during startup refresh.
  • Add new sync/async health check tests covering force_refresh_on_startup(None) and ensuring provided accounts don’t trigger extra fetches.
  • Make test_multimaster header assertions more robust to call ordering by validating counts instead of fixed indices; reduce async flakiness by polling instead of fixed sleep (in one startup failure test).

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
sdk/cosmos/azure-cosmos/azure/cosmos/_global_endpoint_manager.py Sync startup refresh now fetches the database account when None is passed.
sdk/cosmos/azure-cosmos/azure/cosmos/aio/_global_endpoint_manager_async.py Async startup refresh now fetches the database account when None is passed even if _aenter_used=True.
sdk/cosmos/azure-cosmos/tests/test_health_check.py Adds sync regression tests for force_refresh_on_startup(None) and “don’t refetch when account provided”.
sdk/cosmos/azure-cosmos/tests/test_health_check_async.py Adds async regression tests for force_refresh_on_startup(None) and _aenter_used interaction; replaces one fixed sleep with polling.
sdk/cosmos/azure-cosmos/tests/test_multimaster.py Makes tentative-writes header validation resilient to call ordering changes.
sdk/cosmos/azure-cosmos/CHANGELOG.md Adds release note for the None-handling crash fix.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@simorenoh
Copy link
Member

/azp run python - cosmos - tests

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@simorenoh simorenoh merged commit e9c7451 into main Feb 5, 2026
40 checks passed
@simorenoh simorenoh deleted the copilot/port-none-handling-changes branch February 5, 2026 23:59
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.

[Cosmos] port new None handling changes to main branch

3 participants