Repository navigation
[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
Conversation
…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
microsoft-github-policy-service
Bot
requested a review
from Yong Zhang (yonzhan)
October 19, 2026 13:17
Contributor
X Engineering Agent Report |
Member
Author
|
/azp run |
|
Azure Pipelines: Successfully started running 3 pipeline(s). |
Contributor
|
Hi Aditya Pujara (@a0x1ab), |
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 — ️✔️ All clear
Related command
az vm createDescription
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):
Testing Guide
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.History Notes
[Compute]
az vm create: Preserve ARM deployment errors when HTTP response is consumedThis checklist is used to make sure that common guidelines for a pull request are followed.
The PR title and description has followed the guideline in Submitting Pull Requests.
I adhere to the Command Guidelines.
I adhere to the Error Handling Guidelines.
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.