Conversation
️✔️AzureCLI-FullTest
|
️✔️AzureCLI-BreakingChangeTest
|
|
Thank you for your contribution haule21! We will review the pull request and get back to you soon. |
|
Thank you for your contribution! We will review the pull request and get back to you soon. |
|
The git hooks are available for azure-cli and azure-cli-extensions repos. They could help you run required checks before creating the PR. Please sync the latest code with latest dev branch (for azure-cli) or main branch (for azure-cli-extensions). pip install azdev --upgrade
azdev setup -c <your azure-cli repo path> -r <your azure-cli-extensions repo path>
|
@microsoft-github-policy-service agree |
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
Co-authored-by: kai ru <69238381+kairu-ms@users.noreply.github.com>
Co-authored-by: kai ru <69238381+kairu-ms@users.noreply.github.com>
Co-authored-by: kai ru <69238381+kairu-ms@users.noreply.github.com>
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
az consumption usage list: Enhanced handling of usageStart and usageEnd when missing
Co-authored-by: kai ru <69238381+kairu-ms@users.noreply.github.com>
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
|
Hello, @kairu-ms Just wanted to let you know I’ve fixed the whitespace issue that was causing the tests to fail, and I’ve pushed the update. |
haule21
left a comment
There was a problem hiding this comment.
Remove White Space.
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
|
@haule21 thanks for trying to fix this.
even provide here from DEBUG my json retrun: {
"value": [
{
"id": "/subscriptions/57ab3509-zzzz-zzzz-zzzz-zzzzzzzbad2c/providers/Microsoft.Billing/billingPeriods/202504/providers/Microsoft.Consumption/usageDetails/6f5c04c0-zzzz-zzzz-zzzz-zzzzzzzbecb",
"kind": "legacy",
"name": "6f5c04c0-zzzz-zzzz-zzzz-zzzzzzzbecb",
"properties": {
"billingCurrency": "USD",
"billingPeriodEndDate": "2025-04-19T00:00:00.0000000Z",
"billingPeriodStartDate": "2025-03-20T00:00:00.0000000Z",
"billingProfileId": "/subscriptions/57ab3509-zzzz-zzzz-zzzz-zzzzzzzbad2c",
"billingProfileName": "myAZsubName123",
"chargeType": "Usage",
"consumedService": "microsoft.network",
"cost": 0.0864,
"date": "2025-04-01T00:00:00.0000000Z",
"effectivePrice": 0.0036,
"frequency": "UsageBased",
"isAzureCreditEligible": false,
"meterDetails": null,
"meterId": "26ce34b7-67b3-480d-9d1b-54a7fb80f67a",
"offerId": "MS-AZR-0029P",
"product": "IP Addresses - Basic IPv4 Static Public IP",
"publisherType": "Azure",
"quantity": 24,
"resourceGroup": "myAZrg123",
"resourceId": "/subscriptions/57ab3509-zzzz-zzzz-zzzz-zzzzzzzbad2c/resourcegroups/myAZrg123/providers/microsoft.network/publicipaddresses/brava11-ip",
"resourceLocation": "US West 2",
"resourceName": "myp-ip",
"subscriptionId": "57ab3509-zzzz-zzzz-zzzz-zzzzzzzbad2c",
"subscriptionName": "myAZsubName123",
"unitPrice": 0
},
"tags": {
"vf-creator": "joedoe@mycomp.com",
"vf-date-created": "2023-06-14T00:37:22.0315752Z"
},
"type": "Microsoft.Consumption/usageDetails"
},
{
"id": "/subscriptions/57ab3509-zzzz-zzzz-zzzz-zzzzzzzbad2c/providers/Microsoft.Billing/billingPeriods/202504/providers/Microsoft.Consumption/usageDetails/e5b711e6-zzzz-zzzz-zzzz-zzzzzzz52c30ab",
"kind": "legacy",
"name": "e5b711e6-zzzz-zzzz-zzzz-zzzzzzz52c30ab",
"properties": {
"billingCurrency": "USD",
"billingPeriodEndDate": "2025-04-19T00:00:00.0000000Z",
"billingPeriodStartDate": "2025-03-20T00:00:00.0000000Z",
"billingProfileId": "/subscriptions/57ab3509-zzzz-zzzz-zzzz-zzzzzzzbad2c",
"billingProfileName": "myAZsubName123",
"chargeType": "Usage",
"consumedService": "Microsoft.Storage",
"cost": 0.00231012,
"date": "2025-03-29T00:00:00.0000000Z",
"effectivePrice": 0.045,
"frequency": "UsageBased",
"isAzureCreditEligible": false,
"meterDetails": null,
"meterId": "3f2b1e1c-c886-4ec6-ad6f-dd0ef38819c9",
"offerId": "MS-AZR-0029P",
"product": "Tables - LRS Data Stored",
"publisherType": "Azure",
"quantity": 0.051336,
"resourceGroup": "myAZrg123",
"resourceId": "/subscriptions/57ab3509-zzzz-zzzz-zzzz-zzzzzzzbad2c/resourceGroups/myAZrg123/providers/Microsoft.Storage/storageAccounts/mystordiag",
"resourceLocation": "US West 2",
"resourceName": "mystordiag",
"subscriptionId": "57ab3509-zzzz-zzzz-zzzz-zzzzzzzbad2c",
"subscriptionName": "myAZsubName123",
"unitPrice": 0
},
"tags": null,
"type": "Microsoft.Consumption/usageDetails"
}
]
} |
|
Hi, I’m not entirely sure either, but I’ll respond based on my analysis of the source code. From what I can tell, the UsageStart and UsageEnd values appear to be properties that are only included when you have ownership of the Billing Account. If they’re not showing up in your case, it’s likely that your subscription is under an account type that doesn’t have control over the billing account. Please refer to the link below for more details: https://learn.microsoft.com/en-us/azure/cost-management-billing/manage/view-all-accounts |
Handle None UsageStart in consumption usage list and exclude from results
Related command
az consumption usage list: Enhanced handling ofusageStartandusageEndincustom.py:_outputfunction fromresult = list([transform_usage_output(item) for item in result])toresult = list(filter(None, [transform_usage_output(item) for item in result]))to excludeNonevalues returned bytransform_usage_output.transform_usage_outputfunction to:result.get('usageStart', None)andresult.get('usageEnd', None)for safe attribute access.if usageStart and usageEndto returnNoneif either is missing, ensuring invalid entries are filtered out.usageStartandusageEndto ISO 8601 strings (e.g.,"2025-03-01T00:00:00Z") or set to'None'if parsing fails.usageQuantity,billableQuantity,pretaxCost) to useget()with default'None'for robustness.Description
This PR updates the
az consumption usage listcommand to handle cases where theusage_startproperty in the response is missing orNone. Previously, this could lead to potential errors (e.g., TypeError) when processing usage details. Now, usage entries with aNoneusage_startare filtered out from the results, ensuring a more robust and error-free experience.list_usageincustom.pyto filter out usage entries whereusage_startisNone.usage_startin the output, improving reliability.Testing Guide
[Command]
az consumption usage list --end-date 2025-03-24 --start-date 2025-03-01 --output json
usageStartfield.usageStartorusageEndare excluded from the results.History Notes
This checklist is used to make sure that common guidelines for a pull request are followed.
[Consumption]for customer-facing changes, and the description includes purpose, changes, and testing steps as per the guideline.az consumption usage listmaintains consistency with existing patterns, ensures backward compatibility, and handles errors gracefully.get()and filtering ofNonevalues to prevent exceptions likeTypeError.