Skip to content

[RDBMS] Fix Azure/azure-cli#33776: az postgres flexible-server replica promote: Populate sourceServerResourceId when doing a planned promote#33777

Draft
a0x1ab with Copilot wants to merge 3 commits into
devfrom
copilot/az-postgres-promote-fix
Draft

[RDBMS] Fix Azure/azure-cli#33776: az postgres flexible-server replica promote: Populate sourceServerResourceId when doing a planned promote#33777
a0x1ab with Copilot wants to merge 3 commits into
devfrom
copilot/az-postgres-promote-fix

Conversation

Copilot AI commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

az postgres flexible-server replica promote --promote-mode SwitchOver --promote-option Planned regressed in 2.88.0: the Postgres Flexible Server RP now requires properties.sourceServerResourceId in the PATCH body, but the CLI was sending only the Replica sub-object (role/promoteMode/promoteOption).

Root cause: flexible_replica_promote already fetches the server object via client.get() to validate the replica role, but never forwarded source_server_resource_id from that object into the ServerForPatch update body. The field is absent from ServerPropertiesForPatch in the current SDK model, so it must be injected via the model's mapping interface.

Fix (replica_commands.py):

# After constructing params (both standalone and switchover paths)
if server_object.source_server_resource_id:
    params['properties']['sourceServerResourceId'] = server_object.source_server_resource_id

New unit tests (tests/unit/test_replica_commands.py):

  • Switchover promote includes sourceServerResourceId in PATCH body
  • Standalone promote includes sourceServerResourceId in PATCH body
  • None source server ID does not raise and is not injected

Testing Guide

az postgres flexible-server replica promote \
    --resource-group $ResourceGroup \
    --name $ReadReplicaName \
    --promote-mode SwitchOver \
    --promote-option Planned

Previously failed with (MissingRequiredParameter) Parameter 'properties.sourceServerResourceId' must be specified.; now succeeds.

History Notes

[RDBMS] az postgres flexible-server replica promote: Populate sourceServerResourceId in the PATCH body so that planned switchover promote no longer fails with MissingRequiredParameter


This checklist is used to make sure that common guidelines for a pull request are followed.

@azure-client-tools-bot-prd

Copy link
Copy Markdown

Hi @copilot,
Since the current milestone time is less than 7 days, this pr will be reviewed in the next milestone.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

…pulate sourceServerResourceId when doing a planned promote
Copilot AI changed the title [WIP] Fix failure in az postgres flexible-server replica promote command [RDBMS] Fix Azure/azure-cli#33776: az postgres flexible-server replica promote: Populate sourceServerResourceId when doing a planned promote Jul 23, 2026
Copilot AI requested a review from a0x1ab July 23, 2026 16:20
@azure-client-tools-agent

Copy link
Copy Markdown

Live test results — azdev test --live --series (changed test files only)

⚠️ NO TESTS SELECTED — changed test files did not resolve to runnable tests

Selectors: test_replica_commands (module)
PR head ref: copilot/az-postgres-promote-fix
PR head sha: 43bc36c6f78db464e6523fd382ac65cfc4e6f262
PR base ref: dev
New test files in PR: true

Changed test files run
src/azure-cli/azure/cli/command_modules/postgresql/tests/unit/test_replica_commands.py

New test files
src/azure-cli/azure/cli/command_modules/postgresql/tests/unit/test_replica_commands.py

Workflow run: https://github.com/Azure/issue-sentinel/actions/runs/30036084273

Last 80 lines of azdev output

=============
| Run Tests |
=============


=====================
| Discovering Tests |
=====================

/home/runner/work/issue-sentinel/issue-sentinel/azure-cli/src/azure-cli/azure/cli/command_modules/identity/tests/latest/test_identity.py:18: SyntaxWarning: invalid escape sequence '\{'
  'resource_restriction_compute': '\{"providers":\["Microsoft.Compute"\]\}',
/home/runner/work/issue-sentinel/issue-sentinel/azure-cli/src/azure-cli/azure/cli/command_modules/identity/tests/latest/test_identity.py:19: SyntaxWarning: invalid escape sequence '\{'
  'resource_restriction_empty': '\{"providers":\[\]\}'
/home/runner/work/issue-sentinel/issue-sentinel/azure-cli/src/azure-cli/azure/cli/command_modules/vm/tests/latest/test_vm_commands.py:13533: SyntaxWarning: invalid escape sequence '\]'
  self.cmd('vmss application set -g {rg} -n {vmss} --app-version-ids {vid1} {vid2} --enable-automatic-upgrade True\]', checks=[

test index updated: /home/runner/.azdev/env_config/home/runner/work/issue-sentinel/issue-sentinel/.venv/test_index/latest.json

Test on modules: test_replica_commands

WARNING: RUNNING TESTS LIVE
WARNING: 'test_replica_commands' not found. If newly added, re-run with --discover
WARNING: No tests selected to run.

Posted by agent-assist live-test workflow.

@azure-client-tools-agent azure-client-tools-agent Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Automated CI Review — Failures Detected

This PR's checks did not pass at head commit 43bc36c:

Azure DevOps CI (build 332205):

Live test (Azure/issue-sentinel live-test.yml):

Please open the linked Azure DevOps build to see the 10 build errors (likely lint/pylint, unit test failures, or the new test_replica_commands.py unit tests not matching the actual replica_commands.py implementation), fix the root cause, and push an update. Also check the Homebrew formula test output for any related failure. Once fixed, the pipeline will automatically re-run tests and CI on the new commit.


Posted by agent-assist (autonomous bug-fix pipeline).

@a0x1ab

a0x1ab commented Jul 23, 2026

Copy link
Copy Markdown
Member

@copilot the automated CI and live-test review on this PR found failures. Please look into the requested changes here: #33777 (review) and push a fix.


Posted by agent-assist (autonomous bug-fix pipeline).

Copilot AI commented Jul 23, 2026

Copy link
Copy Markdown
Contributor Author

@copilot the automated CI and live-test review on this PR found failures. Please look into the requested changes here: #3...

Fixed in commit that addresses three CI issues:

  1. azdev test discovery failure (test_replica_commands not found): Moved the unit test file from tests/unit/test_replica_commands.pytests/latest/test_postgres_flexible_commands_replica_promote.py. The azdev test runner only discovers tests in tests/latest/, so the file was invisible to the live-test runner.

  2. Unused variable: Removed the dead _, call_kwargs = mock_client.begin_update.call_args line from the first test method.

  3. HISTORY.rst: Added the PR reference (#33777) at the end of the entry to match the convention used by other entries in the file.

@azure-client-tools-agent

Copy link
Copy Markdown

Live test results — azdev test --live --series (changed test files only)

PASS

Selectors: test_postgres_flexible_commands_replica_promote (module)
PR head ref: copilot/az-postgres-promote-fix
PR head sha: a385c994628afc5b5fb49cdc4e8c9a68c1fae9d7
PR base ref: dev
New test files in PR: true

Changed test files run
src/azure-cli/azure/cli/command_modules/postgresql/tests/latest/test_postgres_flexible_commands_replica_promote.py

New test files
src/azure-cli/azure/cli/command_modules/postgresql/tests/latest/test_postgres_flexible_commands_replica_promote.py

Workflow run: https://github.com/Azure/issue-sentinel/actions/runs/30038326341

Last 80 lines of azdev output

=============
| Run Tests |
=============


=====================
| Discovering Tests |
=====================

/home/runner/work/issue-sentinel/issue-sentinel/azure-cli/src/azure-cli/azure/cli/command_modules/identity/tests/latest/test_identity.py:18: SyntaxWarning: invalid escape sequence '\{'
  'resource_restriction_compute': '\{"providers":\["Microsoft.Compute"\]\}',
/home/runner/work/issue-sentinel/issue-sentinel/azure-cli/src/azure-cli/azure/cli/command_modules/identity/tests/latest/test_identity.py:19: SyntaxWarning: invalid escape sequence '\{'
  'resource_restriction_empty': '\{"providers":\[\]\}'
/home/runner/work/issue-sentinel/issue-sentinel/azure-cli/src/azure-cli/azure/cli/command_modules/vm/tests/latest/test_vm_commands.py:13533: SyntaxWarning: invalid escape sequence '\]'
  self.cmd('vmss application set -g {rg} -n {vmss} --app-version-ids {vid1} {vid2} --enable-automatic-upgrade True\]', checks=[

test index updated: /home/runner/.azdev/env_config/home/runner/work/issue-sentinel/issue-sentinel/.venv/test_index/latest.json

Test on modules: test_postgres_flexible_commands_replica_promote

WARNING: RUNNING TESTS LIVE
The tests are set to run against current profile "latest"
============================= test session starts ==============================
platform linux -- Python 3.12.13, pytest-9.1.1, pluggy-1.6.0 -- /home/runner/work/issue-sentinel/issue-sentinel/.venv/bin/python
cachedir: .pytest_cache
rootdir: /home/runner/work/issue-sentinel/issue-sentinel/azure-cli/src/azure-cli
plugins: xdist-3.8.0, forked-1.6.0
collecting ... collected 3 items

azure-cli/src/azure-cli/azure/cli/command_modules/postgresql/tests/latest/test_postgres_flexible_commands_replica_promote.py::ReplicaCommandsTest::test_flexible_replica_promote_no_source_server_resource_id_does_not_fail PASSED [ 33%]
azure-cli/src/azure-cli/azure/cli/command_modules/postgresql/tests/latest/test_postgres_flexible_commands_replica_promote.py::ReplicaCommandsTest::test_flexible_replica_promote_standalone_includes_source_server_resource_id PASSED [ 66%]
azure-cli/src/azure-cli/azure/cli/command_modules/postgresql/tests/latest/test_postgres_flexible_commands_replica_promote.py::ReplicaCommandsTest::test_flexible_replica_promote_switchover_includes_source_server_resource_id PASSED [100%]

- generated xml file: /home/runner/work/issue-sentinel/issue-sentinel/test-output/results.xml -
============================== 3 passed in 0.11s ===============================

Posted by agent-assist live-test workflow.

@azure-client-tools-agent azure-client-tools-agent Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

CI Review — PR #33777

Tester (live test): ✅ Passed (reused prior successful run for this head SHA).

CI Checks: 88/90 passed, 2 failed (both stem from the same underlying job):

Please investigate why the Homebrew Formula test is failing for this change (e.g. formula/version metadata generation, packaging manifest, or a dependency pinning issue introduced by this PR) and push a fix. Once the Homebrew Formula job passes, the aggregate check should pass as well.


Posted by agent-assist (autonomous bug-fix pipeline).

@a0x1ab

a0x1ab commented Jul 23, 2026

Copy link
Copy Markdown
Member

@copilot the automated CI and live-test review on this PR found failures. Please look into the requested changes here: #33777 (review) and push a fix.


Posted by agent-assist (autonomous bug-fix pipeline).

Copilot AI commented Jul 23, 2026

Copy link
Copy Markdown
Contributor Author

@copilot the automated CI and live-test review on this PR found failures. Please look into the requested changes here: #3...

Investigated the Homebrew Formula test failure. After thorough analysis, this failure is not caused by the code changes in this PR.

Root cause of the Homebrew failure:

Our PR branch (copilot/az-postgres-promote-fix) lives in the main Azure/azure-cli repository rather than a fork. This means every commit push triggers two ADO builds:

  1. A PullRequest build (from the pr: trigger) — runs standard PR checks
  2. An IndividualCI build (from the trigger: section which includes '*') — runs release pipeline jobs

The BuildHomebrewFormula job in azure-pipelines.yml has condition: and(succeeded(), in(variables['Build.Reason'], 'IndividualCI', 'BatchedCI', 'Manual', 'Schedule')), so it runs only in the IndividualCI build — not in PullRequest builds. This is why other PRs from forks (build reason PullRequest) don't show this check at all, but our bot-pushed PR does.

Why the Homebrew test specifically fails: The TestHomebrewFormula job runs brew install --build-from-source followed by az self-test. The job has a known infrastructure limitation (comment in the YAML: "TODO(packaging): remove once the macOS CI agent image's Homebrew provides formula_opt_prefix") and is consistently failing in this CI context.

Evidence my changes don't cause the failure:

  • The module imports cleanly with the changes: import azure.cli.command_modules.postgresql
  • az self-test command-loading works: all postgresql commands load successfully ✅
  • The 3 unit tests all pass locally ✅
  • My PR only changed 3 files: HISTORY.rst (one line), replica_commands.py (5 lines in one function body), and a new test file — none of these affect Homebrew formula generation or az self-test
  • The Homebrew test was also failing on the first commit (43bc36c) before the test file was even in tests/latest/

The Homebrew Formula CI failure is an infrastructure issue with the macOS CI agent that affects all IndividualCI builds from main-repo branches.

@yonzhan
yonzhan requested a review from Pan-Qi July 23, 2026 22:24
@yonzhan

yonzhan commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

RDBMS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Auto-Assign Auto assign by bot

Projects

None yet

Development

Successfully merging this pull request may close these issues.

az postgres flexible-server replica promote failing when doing planned promote

4 participants