-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Description
Environment
- Azure CLI Version: 2.77.0
- OS: Linux (Ubuntu 22.04)
- Python: 3.13.7
Describe the bug
Azure CLI deployment validation commands consistently fail with "The content for this response was already consumed" error, completely masking the actual validation errors and making it impossible to validate Bicep templates before deployment.
To Reproduce
- Create any Bicep template (valid or invalid)
- Run validation command:
az deployment group validate --resource-group test-rg --template-file main.bicep --parameters location=eastus
- Observe the error instead of actual validation results
Expected behavior
The command should either:
- Successfully validate the template and show validation results, OR
- Display the actual validation error (e.g., "Resource group 'test-rg' not found")
Actual behavior
Always returns:
The content for this response was already consumed
RuntimeError: The content for this response was already consumed
Stack trace
Traceback (most recent call last):
File "/opt/az/lib/python3.13/site-packages/requests/models.py", line 897, in content
raise RuntimeError("The content for this response was already consumed")
RuntimeError: The content for this response was already consumed
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/az/lib/python3.13/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.13/site-packages/requests/models.py", line 926, in text
if not self.content:
^^^^^^^^^^^^
File "/opt/az/lib/python3.13/site-packages/requests/models.py", line 897, in content
raise RuntimeError("The content for this response was already consumed")
Root cause analysis
The issue occurs in the error handling code path in azure/cli/core/commands/arm.py:
- A legitimate error occurs (e.g., ResourceGroupNotFound)
- Azure CLI attempts to read the HTTP response content to format the error message
- The response content has already been consumed by the Azure SDK
- The second attempt to read content fails with "content already consumed"
- The original error is completely masked
Impact
- Critical: Prevents proper template validation workflows
- Masks real errors: Users cannot see actual validation errors
- Blocks CI/CD: Automated validation scripts fail
- Affects multiple commands: Both
validateandwhat-ifare broken
Workaround
Use local validation tools instead:
# Syntax validation
az bicep build --file template.bicep --stdout > /dev/null
# Best practices check
az bicep lint --file template.bicepAdditional context
This appears to be a regression in error handling where HTTP response content is being consumed multiple times. The fix should ensure response content is not read more than once, or clone the response before initial consumption.