Usage start error using az consumption usage list on Azure CLI version 2.57.0
Describe the bug
az consumption usage list --start-date 2021-10-01 --end-date 2021-11-01
This command is in preview and under development. Reference and support levels: https://aka.ms/CLI_refstatus
The command failed with an unexpected error. Here is the traceback:
'usageStart'
Traceback (most recent call last):
File "/home/raimond/.local/lib/python3.8/site-packages/knack/cli.py", line 233, in invoke
cmd_result = self.invocation.execute(args)
File "/home/raimond/.local/lib/python3.8/site-packages/azure/cli/core/commands/init.py", line 664, in execute
raise ex
File "/home/raimond/.local/lib/python3.8/site-packages/azure/cli/core/commands/init.py", line 729, in _run_jobs_serially
results.append(self._run_job(expanded_arg, cmd_copy))
File "/home/raimond/.local/lib/python3.8/site-packages/azure/cli/core/commands/init.py", line 711, in _run_job
result = list(result)
File "/home/raimond/.local/lib/python3.8/site-packages/azure/cli/core/aaz/_paging.py", line 87, in next
return next(self._page_iterator)
File "/home/raimond/.local/lib/python3.8/site-packages/azure/cli/core/aaz/_paging.py", line 46, in next
curr_page, self._next_link = self._extract_result()
File "/home/raimond/.local/lib/python3.8/site-packages/azure/cli/command_modules/consumption/custom.py", line 85, in _output
result = list([transform_usage_output(item) for item in result])
File "/home/raimond/.local/lib/python3.8/site-packages/azure/cli/command_modules/consumption/custom.py", line 85, in
Related command
az consumption usage list
Errors
The command failed with an unexpected error. Here is the traceback:
'usageStart'
Traceback (most recent call last):
File "/home/raimond/.local/lib/python3.8/site-packages/knack/cli.py", line 233, in invoke
cmd_result = self.invocation.execute(args)
File "/home/raimond/.local/lib/python3.8/site-packages/azure/cli/core/commands/init.py", line 664, in execute
raise ex
File "/home/raimond/.local/lib/python3.8/site-packages/azure/cli/core/commands/init.py", line 729, in _run_jobs_serially
results.append(self._run_job(expanded_arg, cmd_copy))
File "/home/raimond/.local/lib/python3.8/site-packages/azure/cli/core/commands/init.py", line 711, in _run_job
result = list(result)
File "/home/raimond/.local/lib/python3.8/site-packages/azure/cli/core/aaz/_paging.py", line 87, in next
return next(self._page_iterator)
File "/home/raimond/.local/lib/python3.8/site-packages/azure/cli/core/aaz/_paging.py", line 46, in next
curr_page, self._next_link = self._extract_result()
File "/home/raimond/.local/lib/python3.8/site-packages/azure/cli/command_modules/consumption/custom.py", line 85, in _output
result = list([transform_usage_output(item) for item in result])
File "/home/raimond/.local/lib/python3.8/site-packages/azure/cli/command_modules/consumption/custom.py", line 85, in
Issue script & Debug output
Expected behavior
Result from az consumption list
Environment Summary
azure-cli 2.57.0 core 2.57.0 telemetry 1.1.0 Extensions: account 0.2.5 aks-preview 1.0.0b5 application-insights 1.2.0 costmanagement 0.3.0 rdbms-connect 1.0.4 resource-graph 2.1.0 storage-preview 1.0.0b1 virtual-wan 0.3.0
Dependencies: msal 1.26.0 azure-mgmt-resource 23.1.0b2
Python location '/usr/bin/python3' Extensions directory '/home/raimond/.azure/cliextensions'
Python (Linux) 3.8.10 (default, Nov 22 2023, 10:22:35) [GCC 9.4.0]
Your CLI is up-to-date
Additional context
No response
Thank you for opening this issue, we will look into it.
Same issue here.
PS C:\> az consumption usage list --start-date 2024-01-01 --end-date 2024-02-01
This command is in preview and under development. Reference and support levels: https://aka.ms/CLI_refstatus
The command failed with an unexpected error. Here is the traceback:
'usageStart'
Traceback (most recent call last):
File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\knack/cli.py", line 233, in invoke
File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 664, in execute
File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 729, in _run_jobs_serially
File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 711, in _run_job
File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/aaz/_paging.py", line 87, in __next__
File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/aaz/_paging.py", line 46, in __next__
File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/consumption/custom.py", line 85, in _output
File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/consumption/custom.py", line 85, in <listcomp>
File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/consumption/custom.py", line 95, in transform_usage_output
KeyError: 'usageStart'
To check existing issues, please visit: https://github.com/Azure/azure-cli/issues
hi Everyone - I can confirm the same issue.
I am currently running some tests using Azure DevOps Pipelines, and have prepared a pipeline that runs two jobs in parallel, both run the following command against two different subscriptions (service connections) under the same tenant:
az consumption usage list
--billing-period-name $(lastMonth)
--include-additional-properties
--include-meter-details
--query "[].[instanceId, consumedService, instanceName, instanceLocation, product, pretaxCost, usageStart, usageEnd]"
--output tsv
I ran this command 6 times within the span of about 40 minutes:
- 5 of those runs ended up with one of the job failing and the other one working fine (returning results)
- 1 run finished with both jobs completing OK
- strangely enough, while I reliably get an error indicated above, I have not seen both jobs failing yet - only one of those seems to fail at any given run
- this command never returns any errors when I run it from my local (always successful)
Hope that sheds a bit of light and helps your troubleshooting efforts.
urllib3.connectionpool: https://management.azure.com:443 "GET /subscriptions/895cda87-06a5-4a91-b04c-d023ccbc6525/providers/Microsoft.Consumption/usageDetails?$filter=properties%2FusageEnd%20ge%20%272024-01-08T00%3A00%3A00Z%27%20and%20properties%2FusageEnd%20le%20%272024-01-09T00%3A00%3A00Z%27&$top=1&api-version=2023-05-01 HTTP/1.1" 200 2976 cli.azure.cli.core.sdk.policies: Response status: 200
Looks like it gives the response, but a closer look at the url shows that there's 2x usageEnd. First one should be of course usageStart.
I've been facing this issue with my workflow that checks for the az consumption usage list :
ERROR: The command failed with an unexpected error. Here is the traceback:
ERROR: 'usageStart'
Traceback (most recent call last):
File "/opt/az/lib/python3.[11](https://github.com/turbotio/ops/actions/runs/8277743509/job/22648667583#step:6:12)/site-packages/knack/cli.py", line 233, in invoke
cmd_result = self.invocation.execute(args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/az/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py", line 664, in execute
raise ex
File "/opt/az/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py", line 731, in _run_jobs_serially
results.append(self._run_job(expanded_arg, cmd_copy))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/az/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py", line 7[14](https://github.com/turbotio/ops/actions/runs/8277743509/job/22648667583#step:6:15), in _run_job
result = list(result)
^^^^^^^^^^^^
File "/opt/az/lib/python3.11/site-packages/azure/cli/core/aaz/_paging.py", line 87, in __next__
return next(self._page_iterator)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/az/lib/python3.11/site-packages/azure/cli/core/aaz/_paging.py", line 46, in __next__
curr_page, self._next_link = self._extract_result()
^^^^^^^^^^^^^^^^^^^^^^
File "/opt/az/lib/python3.11/site-packages/azure/cli/command_modules/consumption/custom.py", line 85, in _output
result = list([transform_usage_output(item) for item in result])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/az/lib/python3.11/site-packages/azure/cli/command_modules/consumption/custom.py", line 85, in <listcomp>
result = list([transform_usage_output(item) for item in result])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/az/lib/python3.11/site-packages/azure/cli/command_modules/consumption/custom.py", line 95, in transform_usage_output
usageStart = parser.parse(result['usageStart'])
~~~~~~^^^^^^^^^^^^^^
I can confirm that the error still exists also in latest Azure CLI version 2.58.0. Are there meanwhile any updates on this or a workaround to make this work again? It's really bad not to be able to retrieve the detailled cost consumption per ressource via this simple CLI query since meanwhile more than a month.
I'm facing the same issue using Azure CLI version 2.58.0
I am also facing the issue in
az version { "azure-cli": "2.58.0", "azure-cli-core": "2.58.0", "azure-cli-telemetry": "1.1.0", "extensions": {} }
As a workaround you can try an older version
docker run -it mcr.microsoft.com/azure-cli:2.56.0
Still there in 2.61.0
Experiencing it on 2.62.0 as well. az version { "azure-cli": "2.62.0", "azure-cli-core": "2.62.0", "azure-cli-telemetry": "1.1.0", "extensions": { "ai-examples": "0.2.5", "costmanagement": "0.3.0", "ml": "2.28.0", "ssh": "2.0.4" } }
Same here on...
az version { "azure-cli": "2.62.0", "azure-cli-core": "2.62.0", "azure-cli-telemetry": "1.1.0", "extensions": { "ai-examples": "0.2.5", "ml": "2.28.0", "ssh": "2.0.4" } }
I might have found the issue on the following line: https://github.com/Azure/azure-cli/blob/29564830498870c401679e0059fddbbf5851f10c/src/azure-cli/azure/cli/command_modules/consumption/custom.py#L78
The above line reads as follows:
filter_from = "properties/usageEnd ge \'{}\'".format(start_date.strftime("%Y-%m-%dT%H:%M:%SZ"))
Note that in the above line the filter from is using usageEnd instead of usageStart.
The fixed line should read as follows:
filter_from = "properties/usageStart ge \'{}\'".format(start_date.strftime("%Y-%m-%dT%H:%M:%SZ"))
Is there someone around who can test the above code changes?
While the usageEnd/usageStart noted above seems to indeed be a problem, I patched it manually on my install (now 2.63.0) and this error still happens.
Down in the transform_error_output where the error happens, I added a dump of results and it doesn't have the usageStart and usageEnd the code is looking for, or any of the other keys the function wants. The output looks like this:
{
"id": "...",
"name": "...",
"accountName": "...",
"consumedService": "...",
"costCenter": "...",
"meterId": "...",
"product": "...",
"subscriptionName": "...",
"tags": {
"..."
},
"type": "..."
}
Still there in 2.65.0
Issue still persists in current latest CLI version 2.67.0.
I wish this would be fixed soon, as the cost management UI is quite painful to use at the moment, even if you just want to gather a simple total cost of multiple subscriptions.
I am also facing the issue with the below cli version. Please try to fix it asap. It's quite painful to get the data manually from the portal for all the resources in each subscription for a tenant and I have multiple tenants to retrieve this data for.
{
"azure-cli": "2.65.0",
"azure-cli-core": "2.65.0",
"azure-cli-telemetry": "1.1.0",
"extensions": {
"ai-examples": "0.2.5",
"ml": "2.30.1",
"ssh": "2.0.5"
}
}
The issue still persists
Error still happens in 2.68.0
➜ az version
{
"azure-cli": "2.68.0",
"azure-cli-core": "2.68.0",
"azure-cli-telemetry": "1.1.0",
"extensions": {
"application-insights": "1.2.2",
"bastion": "1.3.1",
"ssh": "2.0.6",
"subscription": "1.0.0b2"
}
}
Issue still present
PS C:\Git> az version { "azure-cli": "2.68.0", "azure-cli-core": "2.68.0", "azure-cli-telemetry": "1.1.0", "extensions": { "azure-devops": "0.25.0", "managementpartner": "0.1.3", "resource-graph": "2.1.0" } }
PS C:\Git> az consumption usage list --end-date 2025-01-02 --start-date 2019-01-01
This command is in preview and under development. Reference and support levels: https://aka.ms/CLI_refstatus
The command failed with an unexpected error. Here is the traceback:
'usageStart'
Traceback (most recent call last):
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\knack/cli.py", line 233, in invoke
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/init.py", line 666, in execute
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/init.py", line 734, in _run_jobs_serially
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/init.py", line 716, in _run_job
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/aaz/_paging.py", line 87, in next
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/aaz/_paging.py", line 46, in next
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/consumption/custom.py", line 85, in _output
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/consumption/custom.py", line 95, in transform_usage_output
KeyError: 'usageStart'
To check existing issues, please visit: https://github.com/Azure/azure-cli/issues
Microsoft at its finest - more than a year that a basic command does not work with no resolution in sight. sigh.
That's nothing - az storage blob copy has had a bug where supplying "--requires-sync true" causes it to crash for five years and they still haven't even removed the option from the documentation.
And they have the cheek to claim they've made some groundbreaking advanced in quantum computing! I highly doubt it.
While the usageEnd/usageStart noted above seems to indeed be a problem, I patched it manually on my install (now 2.63.0) and this error still happens.
Down in the
transform_error_outputwhere the error happens, I added a dump ofresultsand it doesn't have theusageStartandusageEndthe code is looking for, or any of the other keys the function wants. The output looks like this:{ "id": "...", "name": "...", "accountName": "...", "consumedService": "...", "costCenter": "...", "meterId": "...", "product": "...", "subscriptionName": "...", "tags": { "..." }, "type": "..." }
I believe this was introduced by the API version change in #27833
Error is gone for me with below azure cli version but I don't get any output;
{
"azure-cli": "2.72.0",
"azure-cli-core": "2.72.0",
"azure-cli-telemetry": "1.1.0",
"extensions": {
"account": "0.2.5",
"aks-preview": "14.0.0b1",
"containerapp": "1.0.0b1",
"quota": "1.0.0",
"resource-graph": "2.1.1",
"ssh": "2.0.6"
}
}
cmd I tested
sub='90zzzzzzzzzzzzzzzzz'
az consumption usage list --start-date 2025-03-06 --end-date 2025-04-05 --subscription $sub
in debug I can see that this URL is called
DEBUG: urllib3.connectionpool: https://management.azure.com:443 "GET /subscriptions/90zzzzzzzzzzzzzzz/providers/Microsoft.Consumption/usageDetails?$filter=properties%2FusageEnd%20ge%20%272025-03-06T00%3A00%3A00Z%27%20and%20properties%2FusageEnd%20le%20%272025-04-05T00%3A00%3A00Z%27&api-version=2023-05-01 HTTP/1.1" 200 796444
and get back in DEBUG: cli.azure.cli.core.sdk.policies: Response content: a JSON with like 20k lines
see https://github.com/Azure/azure-cli/pull/31128 and https://github.com/Azure/azure-cli/commit/0140fd739a22dc4db453fa2fd2b449179961cc2f