Skip to content

[Core] Fix #34509: az vm create: Show the original deployment error instead of RuntimeError: The content for this response was already consumed - #34527

Open
Himanshu Rajpurohit (himanshu98-git) wants to merge 1 commit into
Azure:devfrom
himanshu98-git:fix/deployment-error-consumed-response

Conversation

@himanshu98-git

@himanshu98-git Himanshu Rajpurohit (himanshu98-git) commented Dec 4, 2026 •

Copy link
Copy Markdown

🤖 PR Validation — ⚠️ Review suggested

Breaking Changes Tests Suppressions
️✔️ None ️✔️ 130/130 ⚠️ 1 added

This PR adds warning or check suppressions. Fix the underlying warning where possible and justify each remaining suppression in a code comment or the PR description.

1 added suppression
File Line Kind Code
src/azure-cli-core/azure/cli/core/commands/arm.py 116 pylint except Exception: # pylint: disable=broad-except

Related command
az vm create (and other template-based commands using handle_template_based_exception: az vm availability-set create, az vmss create, az network lb create, az network vpn-connection create, ...)

Description
Fixes #34509

When a template deployment fails (e.g. SkuNotAvailable, RequestDisallowedByPolicy), the CLI shows RuntimeError: The content for this response was already consumed instead of the deployment error.

Root cause: the generated SDK sends the initial LRO request with stream=True and calls response.read() before raising HttpResponseError. read() loads the body into the azure-core response's cache by iterating the underlying requests stream, which marks the raw requests.Response as consumed. handle_template_based_exception then reads ex.response.internal_response.text (the raw requests response), which raises RuntimeError.

Fix: read the body through the azure-core response (ex.response.text()), which returns the cached content, and fall back to str(ex) if the body can't be read. For responses whose stream wasn't consumed, behaviour is unchanged (same body text).

Testing Guide

  • Added azure/cli/core/commands/tests/test_arm.py, which builds a real RestRequestsTransportResponse whose stream has been consumed via read(), as the SDK does, and checks that handle_template_based_exception raises InvalidTemplateError / DeploymentError with the original error body. Both tests fail on dev with the exact RuntimeError from the issue and pass with this change.
  • flake8 and pylint clean.

History Notes
[Core] Fix #34509: az vm create: Show the original deployment error instead of RuntimeError: The content for this response was already consumed


…ror instead of RuntimeError

The SDK consumes the raw requests stream when loading the error body, so reading ex.response.internal_response.text raised RuntimeError. Read the cached body via ex.response.text() instead, falling back to str(ex).
Copilot AI balanced review requested due to automatic review settings December 4, 2026 08:24
@azure-pipelines

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

@microsoft-github-policy-service microsoft-github-policy-service Bot added the customer-reported Issues that are reported by GitHub users external to the Azure organization. label Dec 4, 2026
@microsoft-github-policy-service

Copy link
Copy Markdown
Contributor

Thank you for your contribution Himanshu Rajpurohit (@himanshu98-git)! We will review the pull request and get back to you soon.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues were identified in the change to preserve original deployment errors.

No open issues 🎉

What changed in this PR

Fixes #34509 by preserving original deployment errors in az vm create and other template-based commands instead of masking them with a consumed-response error.

Changes:

  • Reads cached response text through azure-core, falling back to str(ex) if reading fails.
  • Adds regression tests for consumed responses producing InvalidTemplateError and DeploymentError.
File Description
src/​azure-cli-core/​azure/​cli/​core/​commands/​tests/​test_arm.py Adds consumed-response regression tests.
src/​azure-cli-core/​azure/​cli/​core/​commands/​arm.py Uses cached response text with an exception-message fallback.

Review effort: Balanced

@yonzhan

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

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

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

act-observability-squad act-platform-engineering-squad Compute az vm/vmss/image/disk/snapshot Core CLI core infrastructure customer-reported Issues that are reported by GitHub users external to the Azure organization.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

az vm create surfaces RuntimeError "The content for this response was already consumed" and hides underlying deployment validation errors

6 participants