Repository navigation
az vm create: RuntimeError('already consumed') masks the real deployment error (SkuNotAvailable/QuotaExceeded) #34083
Description
Describe the bug
When az vm create fails a deployment (e.g. SkuNotAvailable due to capacity restrictions, or QuotaExceeded), the CLI's own error-handling path throws a second, unrelated exception while trying to format the first one, so the top-level failure the user sees is a confusing internal traceback (RuntimeError: The content for this response was already consumed) instead of a clean error message. The real Azure error is still present deeper in the traceback text, but it's buried under CLI-internal noise.
Related command
az vm create \
--resource-group <rg> \
--name <vm> \
--image Win2022Datacenter \
--size Standard_B2s \
--admin-username <user> \
--admin-password <redacted> \
--public-ip-address "" \
--storage-sku StandardSSD_LRS
This reproduced consistently across multiple regions (westeurope, northeurope, eastus) and multiple VM sizes (Standard_B2s, Standard_B2ms, Standard_D2s_v3, Standard_D2s_v5, Standard_B1s) whenever the underlying deployment failed - both for SkuNotAvailable (capacity restriction) and QuotaExceeded failures.
Errors
Traceback (most recent call last):
File "/opt/az/lib/python3.14/site-packages/azure/cli/core/commands/arm.py", line 109, in handle_template_based_exception
raise CLIError(ex.inner_exception.error.message)
^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'error'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/az/lib/python3.14/site-packages/knack/cli.py", line 233, in invoke
cmd_result = self.invocation.execute(args)
File "/opt/az/lib/python3.14/site-packages/azure/cli/core/commands/__init__.py", line 677, in execute
raise ex
File "/opt/az/lib/python3.14/site-packages/azure/cli/core/commands/__init__.py", line 820, in _run_jobs_serially
results.append(self._run_job(expanded_arg, cmd_copy))
File "/opt/az/lib/python3.14/site-packages/azure/cli/core/commands/__init__.py", line 812, in _run_job
return cmd_copy.exception_handler(ex)
File "/opt/az/lib/python3.14/site-packages/azure/cli/core/commands/arm.py", line 112, in handle_template_based_exception
raise_subdivision_deployment_error(ex.response.internal_response.text, ex.error.code if ex.error else None)
File "/opt/az/lib/python3.14/site-packages/requests/models.py", line 928, in text
if not self.content:
File "/opt/az/lib/python3.14/site-packages/requests/models.py", line 899, in content
raise RuntimeError("The content for this response was already consumed")
RuntimeError: The content for this response was already consumed
The genuine deployment error (e.g.):
(SkuNotAvailable) The requested VM size for resource 'Following SKUs have failed for Capacity Restrictions: Standard_B2s' is currently not available in location 'eastus'. Please try another size or deploy to a different location or different zone.
or
Code: QuotaExceeded
Message: Operation could not be completed as it results in exceeding approved standardDSv5Family Cores quota. ... Current Limit: 0, Current Usage: 0, Additional Required: 2 ...
...is present in the exception text at that point, but raise_subdivision_deployment_error tries to read ex.response.internal_response.text a second time after requests has already consumed the stream, so formatting it throws RuntimeError instead of surfacing the message.
Expected behavior
A failed deployment (capacity, quota, or otherwise) should surface a single, clean error message from the actual Azure response - not a RuntimeError about an already-consumed HTTP response body masking it.
Environment summary
{
"azure-cli": "2.89.1",
"azure-cli-core": "2.89.1",
"azure-cli-telemetry": "1.1.0"
}
- OS: Linux (Ubuntu-based), Python 3.14
- Reproduced with both
Microsoft.Compute/virtualMachinesclassicaz vm createdeployments across three regions and five VM sizes.
Activity
azure-client-tools-bot-prd commentedon Sep 15, 2026
Hi robster7674,
2.89.1 is not the latest Azure CLI(2.90.0).
If you haven't already attempted to do so, please upgrade to the latest Azure CLI version by following https://learn.microsoft.com/en-us/cli/azure/update-azure-cli.
yonzhan commentedon Sep 15, 2026
Thank you for opening this issue, we will look into it.
microsoft-github-policy-service commentedon Sep 19, 2026
🔔 Routing this issue to @Azure/act-observability-squad.
x-engineering-agent commentedon Sep 19, 2026
X Engineering Agent Bug Analysis
Below is my analysis of this issue:
Summary
When an ARM-backed az vm create deployment fails, the reporter gets an unrelated RuntimeError about consumed HTTP content instead of the Azure deployment error. The BAMI sandbox reproduced this on Azure CLI 2.89.1, 2.91.0, and the current dev build with InvalidTemplateDeployment. Preserve the original service error so users can diagnose capacity or quota failures.
Likely root cause
The shared ARM template exception handler reads ex.inner_exception.error.message, then handles a missing inner_exception by reading ex.response.internal_response.text. For a streamed requests response whose uncached body was already consumed by the SDK, that read raises RuntimeError and replaces the original deployment error.
Affected code
src/azure-cli-core/azure/cli/core/commands/arm.py›handle_template_based_exception(line 107)src/azure-cli/azure/cli/command_modules/vm/commands.py›load_command_table(line 168)Ruled out
Proposed change
Preserve the existing fix in PR #34238: in core/commands/arm.py handle_template_based_exception use the SDK-parsed HttpResponseError message when the inner exception is absent, without rereading consumed HTTP content; retain usable inner messages and InvalidTemplateDeployment classification. Refresh that PR with a live VM scenario covering the service error if it is missing.
Origin
Why this surfaced now
The handler lines predate the reports and have not materially changed since 2021; a specific SDK, requests, or service change triggering the observed stream state is unconfirmed. The 2026-03 requests and azure-core upgrades postdate earlier reports, so they cannot be the initial cause.
Earlier related reports
Blast radius
Technical details
Evidence
Test plan
Add a recorded vm/tests/latest ScenarioTest invoking az vm create against Azure with an unavailable VM size or zero-quota family so ARM returns an InvalidTemplateDeployment; assert the Azure error code and message survive without consumed-content RuntimeError. Record the test in the live-test lane, and rerun the same BAMI sandbox reproduction on the PR head. Complement it with SDK/requests unit tests for consumed streams, absent inner_exception, populated inner error, and non-SDK fallback; exercise deployment group validate as another caller of the shared handler.
Generated code: Handwritten code. azure-cli-core/azure/cli/core/commands/arm.py is handwritten, outside the AAZ and AutoRest generated trees.
Live reproduction (BAMI sandbox) — Reproduced
Verdict: Reproduced on the current build.
InvalidTemplateDeployment, exit 1InvalidTemplateDeployment, exit 1InvalidTemplateDeployment, exit 1Steps run (redacted)
2.89.1 (reported)
2.91.0 (latest)
dev @ 0fb5754
Sandbox run
Commands ran in an isolated Azure sandbox subscription from a validated ReproSpec; output is redacted.
Posted by x-engineering-agent (Fixer)
12 remaining items
[Compute] Fix Azure#34083: `az vm create`: Preserve ARM deployment er…