Conversation
…ving source region in top-level location The priority-0 location override added in 2cf7b76 clobbered the source region passed by `cli_cosmosdb_restore` with the target region, causing the backend to reject CRR with: "Location provided in 'restoreSource' does not match the location of the request". Gate the override behind `not is_restore_request` so the restore path preserves the source region per the Cosmos ARM contract (top-level location = source, properties.locations[0] = target). Regular create behavior is unchanged. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
️✔️AzureCLI-FullTest
|
️✔️AzureCLI-BreakingChangeTest
|
|
Thank you for your contribution! We will review the pull request and get back to you soon. |
|
The git hooks are available for azure-cli and azure-cli-extensions repos. They could help you run required checks before creating the PR. Please sync the latest code with latest dev branch (for azure-cli) or main branch (for azure-cli-extensions). pip install azdev --upgrade
azdev setup -c <your azure-cli repo path> -r <your azure-cli-extensions repo path>
|
There was a problem hiding this comment.
Pull request overview
Fixes a regression in az cosmosdb restore cross-region restore by preventing _create_database_account from overwriting the restore source region (arm_location) with the priority-0 target region.
Changes:
- Skip
arm_locationnormalization to priority-0locationswhenis_restore_request=True. - Add unit tests covering cross-region restore location preservation and normal create behavior.
- Add a release history entry for the restore fix.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py |
Gate the priority-0 location normalization so restore requests preserve the source region in the top-level ARM location. |
src/azure-cli/azure/cli/command_modules/cosmosdb/tests/latest/test_cosmosdb_backuprestore_scenario.py |
Add regression/control unit tests validating location behavior for restore vs normal create. |
src/azure-cli/HISTORY.rst |
Document the az cosmosdb restore cross-region restore fix in release notes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Related command
az cosmosdb restoreDescription
Fixes a regression in cross-region restore (CRR) introduced by commit
2cf7b76a(PR #32752).That commit added an unconditional loop in
_create_database_accountthat overwritesarm_locationwith the priority-0 entry oflocations:For a regular create this is a defensive no-op. But
cli_cosmosdb_restoredeliberately passes:arm_location= restorable account's region (source, e.g.eastus2)locations=[Location(location_name=<--location>, failover_priority=0)](target, e.g.westus2)is_restore_request=TrueAfter the loop,
arm_locationis clobbered with the target region, so the wire payload becomes:The backend's
ParseAndValidateRestoreSourceUrienforces that the top-levellocationmatches the source URI region and rejects the request:This breaks every cross-region restore via CLI.
Fix
Gate the override on non-restore requests:
This preserves the Cosmos ARM contract for restore (top-level
location= source,properties.locations[0]= target) and keeps the loop's existing behavior for regular create. The unrelated 403 retry-via-GET workaround from #32752 (the documented purpose of that PR) is untouched.Testing
Added two unit tests to
CosmosDBRestoreUnitTests:test_restore_preserves_source_arm_location_for_cross_region— assertslocation='eastus2'is forwarded whenis_restore_request=Trueeven with priority-0 locationwestus2. Would have caught2cf7b76a.test_normal_create_aligns_arm_location_with_priority_zero— counterpart asserting the override still happens for normal create.Local results:
History notes
[Cosmos DB]az cosmosdb restore: Preserve source region in top-level location for cross-region restore