Skip to content

[Compute] Fix #34083: az vm create: Preserve ARM deployment errors when HTTP response is consumed - #34238

Draft
Aditya Pujara (a0x1ab) wants to merge 1 commit into
Azure:devfrom
a0x1ab:agent-assist/azure-azure-cli-issue-34083-83ae08b33ea9
Draft

Aditya Pujara (a0x1ab) wants to merge 1 commit into
Azure:devfrom
a0x1ab:agent-assist/azure-azure-cli-issue-34083-83ae08b33ea9

Conversation

@a0x1ab

@a0x1ab Aditya Pujara (a0x1ab) commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

🤖 PR Validation — ️✔️ All clear

Breaking Changes Tests
️✔️ None ️✔️ 130/130

Related command

az vm create

Description

Fixes #34083.

Supersedes #34102 (closed as stale after 30 days without human activity). This rework was regenerated from a fresh analysis of the issue against the current base branch.
Now also changes: src/azure-cli/azure/cli/command_modules/vm/tests/latest/test_vm_create_errors.py.

Preserve ARM deployment errors when HTTP response is consumed.

Root cause: src/azure-cli-core/azure/cli/core/commands/arm.py:handle_template_based_exception catches AttributeError from a missing inner_exception and directly reads ex.response.internal_response.text. A requests streaming response whose uncached content has already been consumed raises RuntimeError here, masking the Azure deployment failure. HttpResponseError already retains the SDK-formatted Azure code, message and nested details. src/azure-cli/azure/cli/command_modules/vm/commands.py:load_command_table registers this shared handler for vm create; raise_subdivision_deployment_error provides DeploymentError/InvalidTemplateError classification.

Fix: Added an HttpResponseError-specific fallback to use ex.message, which already contains the SDK-parsed Azure error code, message and details, without rereading the HTTP body. Preserve InvalidTemplateDeployment categorization, usable inner exceptions and non-SDK fallback behavior. Added focused core regressions and registered vm create invocation coverage.

Risks and limitations (from the job report):

  • The sandbox did not execute live VM creation. Local SDK/requests regressions do not establish live …
  • Repository CI and Azure live-test lanes remain required. Installed validation reports azdev-linter not run due …
  • Modern SDK deployment errors are rendered from the SDK-formatted message instead of raw response JSON. …

Testing Guide

  • Trusted validation passed (1 command).
  • New or changed tests fail on the base revision and pass with the change: src/azure-cli-core/azure/cli/core/commands/tests/test_arm.py::TestTemplateBasedException::test_template_exception_consumed_invalid_template, src/azure-cli-core/azure/cli/core/commands/tests/test_arm.py::TestTemplateBasedException::test_template_exception_consumed_message_without_parsed_error, src/azure-cli-core/azure/cli/core/commands/tests/test_arm.py::TestTemplateBasedException::test_template_exception_consumed_nested_error.
  • Unit tests: 16 executed, 0 skipped.
  • Recorded scenario tests replayed offline: 14 executed.
  • flake8 and pylint passed.
  • Pre-publication gates passed: release-artifact, generated-ownership, command-help, regression-test, independent-review.
  • Repository CI and live tests run on this PR.

History Notes

[Compute] az vm create: Preserve ARM deployment errors when HTTP response is consumed


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

Independent review: an independent reviewer checked this change against 10 acceptance criteria derived from the issue (7 required); every required criterion is backed by evidence in the diff.

…rors when HTTP response is consumed

Root cause: src/azure-cli-core/azure/cli/core/commands/arm.py:handle_template_based_exception
catches AttributeError from a missing inner_exception and directly reads
ex.response.internal_response.text. A requests streaming response whose
uncached content has already been consumed raises RuntimeError here,
masking the Azure deployment failure. HttpResponseError already retains
the SDK-formatted Azure code, message and nested details.
src/azure-cli/azure/cli/command_modules/vm/commands.py:load_command_table
registers this shared handler for vm create;
raise_subdivision_deployment_error provides
DeploymentError/InvalidTemplateError classification.

Change: Added an HttpResponseError-specific fallback to use ex.message,
which already contains the SDK-parsed Azure error code, message and
details, without rereading the HTTP body. Preserve
InvalidTemplateDeployment categorization, usable inner exceptions and
non-SDK fallback behavior. Added focused core regressions and registered
vm create invocation coverage.

Alternatives considered:
- Catch RuntimeError around response.text: rejected because it still
  rereads a consumed stream and could mask unrelated RuntimeErrors.
- Change only vm create: rejected because the root cause is the shared
  handwritten template exception handler.

Verified:
- Trusted validation passed (1 command).
- New or changed tests fail on the base revision and pass with the
  change:
  `src/azure-cli-core/azure/cli/core/commands/tests/test_arm.py::TestTemplateBasedException::test_template_exception_consumed_invalid_template`,
  `src/azure-cli-core/azure/cli/core/commands/tests/test_arm.py::TestTemplateBasedException::test_template_exception_consumed_message_without_parsed_error`,
  `src/azure-cli-core/azure/cli/core/commands/tests/test_arm.py::TestTemplateBasedException::test_template_exception_consumed_nested_error`.
- Unit tests: 16 executed, 0 skipped.
- Recorded scenario tests replayed offline: 14 executed.
- flake8 and pylint passed.
- Pre-publication gates passed: release-artifact, generated-ownership,
  command-help, regression-test, independent-review.
- Repository CI and live tests run on this PR.

Fixes Azure#34083
@x-engineering-agent x-engineering-agent Bot added Request X Engineering Agent Ask the agent to triage this issue or review this PR X Engineering Agent Generated Agent opened this PR do-not-merge labels Oct 19, 2026
@microsoft-github-policy-service microsoft-github-policy-service Bot added the Auto-Assign Auto assign by bot label Oct 19, 2026
@x-engineering-agent

x-engineering-agent Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

X Engineering Agent Report

Live test — Failed

Workflow concluded failure.

Workflow run

Posted by x-engineering-agent (Tester)

@a0x1ab

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

@x-engineering-agent

Copy link
Copy Markdown
Contributor

Hi Aditya Pujara (@a0x1ab),
Since the current milestone time is less than 7 days, this pr will be reviewed in the next milestone.

This branch has not been deployed

No deployments
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 do-not-merge Request X Engineering Agent Ask the agent to triage this issue or review this PR X Engineering Agent Generated Agent opened this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

az vm create: RuntimeError('already consumed') masks the real deployment error (SkuNotAvailable/QuotaExceeded)

1 participant