Repository navigation
[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
Conversation
…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).
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Thank you for your contribution Himanshu Rajpurohit (@himanshu98-git)! We will review the pull request and get back to you soon. |
Contributor
There was a problem hiding this comment.
🟢 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
InvalidTemplateErrorandDeploymentError.
| 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
Collaborator
|
/azp run |
|
Azure Pipelines: Successfully started running 3 pipeline(s). |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 PR Validation —⚠️ Review suggested
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
src/azure-cli-core/azure/cli/core/commands/arm.pyexcept Exception: # pylint: disable=broad-exceptRelated command
az vm create(and other template-based commands usinghandle_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 showsRuntimeError: The content for this response was already consumedinstead of the deployment error.Root cause: the generated SDK sends the initial LRO request with
stream=Trueand callsresponse.read()before raisingHttpResponseError.read()loads the body into the azure-core response's cache by iterating the underlyingrequestsstream, which marks the rawrequests.Responseas consumed.handle_template_based_exceptionthen readsex.response.internal_response.text(the rawrequestsresponse), which raisesRuntimeError.Fix: read the body through the azure-core response (
ex.response.text()), which returns the cached content, and fall back tostr(ex)if the body can't be read. For responses whose stream wasn't consumed, behaviour is unchanged (same body text).Testing Guide
azure/cli/core/commands/tests/test_arm.py, which builds a realRestRequestsTransportResponsewhose stream has been consumed viaread(), as the SDK does, and checks thathandle_template_based_exceptionraisesInvalidTemplateError/DeploymentErrorwith the original error body. Both tests fail ondevwith the exactRuntimeErrorfrom the issue and pass with this change.History Notes
[Core] Fix #34509:
az vm create: Show the original deployment error instead ofRuntimeError: The content for this response was already consumed