consumption SDK usage_details.list does not filter by date
- Package Name: https://github.com/Azure/azure-sdk-for-python/tree/fd643a07a08f5ae912344c45f91ecd7278e9049b/sdk/consumption/azure-mgmt-consumption
- Package Version: 3.0.0, 8.0.0b1, 8.0.0
- Operating System: linux (ubuntu)
- Python Version: 3.8.10
Describe the bug We are developing a new feature and we use the Azure SDK Consumption client to fetch data from azure.
To Reproduce Steps to reproduce the behavior:
from azure.mgmt.consumption import ConsumptionManagementClient
from azure.identity import ClientSecretCredential
credential = ClientSecretCredential(tenant_id=account_number, client_id=access_key, client_secret=secret)
subscription_id = "some_subscription_id"
consumption_client = ConsumptionManagementClient(credential, subscription_id)
date_filter = "properties/usageStart ge '2021-05-01' AND properties/usageStart lt '2021-02-27'"
data_list = consumption_client.usage_details.list(scope='/subscriptions/subscription_id', filter=date_filter)
data = [item.as_dict() for item in data_list]
print(data)
if we use the filter from the azure consumption SDK test: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/consumption/azure-mgmt-consumption/tests/test_mgmt_consumption.py
for example:
endDate = '2021-05-28T00:00:00Z'
date_filter ='usageEnd le '+ str(endDate)
following this example:

and after that, the same thing, we don't get results for the required period, instead, we get everything for June.
These DateTime filters do not work on azure python SDK Consumption client and usage_details.list()
Expected behavior I expected the results to only return usage items where date_property matched the date filter. Instead, I get everything for June (I guess always returns everything for the current month, and the consumption client seems to simply ignore the DateTime range filters).
Screenshots If applicable, add screenshots to help explain your problem.

Additional context Add any other context about the problem here.
Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @ms-premp.
Issue Details
- Package Name: https://github.com/Azure/azure-sdk-for-python/tree/fd643a07a08f5ae912344c45f91ecd7278e9049b/sdk/consumption/azure-mgmt-consumption
- Package Version: 3.0.0, 8.0.0b1, 8.0.0
- Operating System: linux (ubuntu)
- Python Version: 3.8.10
Describe the bug We are developing a new feature and we use the Azure SDK Consumption client to fetch data from azure.
To Reproduce Steps to reproduce the behavior:
from azure.mgmt.consumption import ConsumptionManagementClient
from azure.identity import ClientSecretCredential
credential = ClientSecretCredential(tenant_id=account_number, client_id=access_key, client_secret=secret)
subscription_id = "some_subscription_id"
consumption_client = ConsumptionManagementClient(credential, subscription_id)
date_filter = "properties/usageStart ge '2021-05-01' AND properties/usageStart lt '2021-02-27'"
data_list = consumption_client.usage_details.list(scope='/subscriptions/subscription_id', filter=date_filter)
data = [item.as_dict() for item in data_list]
print(data)
if we use the filter from the azure consumption SDK test: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/consumption/azure-mgmt-consumption/tests/test_mgmt_consumption.py
for example:
endDate = '2021-05-28T00:00:00Z'
date_filter ='usageEnd le '+ str(endDate)
following this example:

and after that, the same thing, we don't get results for the required period, instead, we get everything for June.
These DateTime filters do not work on azure python SDK Consumption client and usage_details.list()
Expected behavior I expected the results to only return usage items where date_property matched the date filter. Instead, I get everything for June (I guess always returns everything for the current month, and the consumption client seems to simply ignore the DateTime range filters).
Screenshots If applicable, add screenshots to help explain your problem.

Additional context Add any other context about the problem here.
| Author: | izilic333 |
|---|---|
| Assignees: | - |
| Labels: |
|
| Milestone: | - |
Thanks for your feedback, we'll investigate asap.
Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @TiagoCrewGitHubIssues.
Issue Details
- Package Name: https://github.com/Azure/azure-sdk-for-python/tree/fd643a07a08f5ae912344c45f91ecd7278e9049b/sdk/consumption/azure-mgmt-consumption
- Package Version: 3.0.0, 8.0.0b1, 8.0.0
- Operating System: linux (ubuntu)
- Python Version: 3.8.10
Describe the bug We are developing a new feature and we use the Azure SDK Consumption client to fetch data from azure.
To Reproduce Steps to reproduce the behavior:
from azure.mgmt.consumption import ConsumptionManagementClient
from azure.identity import ClientSecretCredential
credential = ClientSecretCredential(tenant_id=account_number, client_id=access_key, client_secret=secret)
subscription_id = "some_subscription_id"
consumption_client = ConsumptionManagementClient(credential, subscription_id)
date_filter = "properties/usageStart ge '2021-05-01' AND properties/usageStart lt '2021-02-27'"
data_list = consumption_client.usage_details.list(scope='/subscriptions/subscription_id', filter=date_filter)
data = [item.as_dict() for item in data_list]
print(data)
if we use the filter from the azure consumption SDK test: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/consumption/azure-mgmt-consumption/tests/test_mgmt_consumption.py
for example:
endDate = '2021-05-28T00:00:00Z'
date_filter ='usageEnd le '+ str(endDate)
following this example:

and after that, the same thing, we don't get results for the required period, instead, we get everything for June.
These DateTime filters do not work on azure python SDK Consumption client and usage_details.list()
Expected behavior I expected the results to only return usage items where date_property matched the date filter. Instead, I get everything for June (I guess always returns everything for the current month, and the consumption client seems to simply ignore the DateTime range filters).
Screenshots If applicable, add screenshots to help explain your problem.

Additional context Add any other context about the problem here.
| Author: | izilic333 |
|---|---|
| Assignees: | msyyc |
| Labels: |
|
| Milestone: | - |
Here is one way you can monkey patch the client to work around this omission in the SDK. Is there a better workaround?
filter_date = "2021-08-01"
# Monkey patch client to include startDate and endDate in URL
url_parts = list(urlparse.urlparse(client.usage_details.list.metadata['url']))
query = {"startDate": filter_date, "endDate": filter_date}
url_parts[4] = urlencode(query)
client.usage_details.list.metadata['url'] = urlparse.urlunparse(url_parts)
The above example will retrieve one day's worth of records for 2021-08-01.
Here is one way you can monkey patch the client to work around this omission in the SDK. Is there a better workaround?
filter_date = "2021-08-01" # Monkey patch client to include startDate and endDate in URL url_parts = list(urlparse.urlparse(client.usage_details.list.metadata['url'])) query = {"startDate": filter_date, "endDate": filter_date} url_parts[4] = urlencode(query) client.usage_details.list.metadata['url'] = urlparse.urlunparse(url_parts)The above example will retrieve one day's worth of records for 2021-08-01.
Thanks for this monkey patch! With this at least we can use SDK instead of plain API.
we are working on validating the newer version of python sdk for cost management. will update once the validation is completed and released.
Hi @izilic333. Thank you for opening this issue and giving us the opportunity to assist. We believe that this has been addressed. If you feel that further discussion is needed, please add a comment with the text “/unresolve” to remove the “issue-addressed” label and continue the conversation.
Hi @izilic333, since you haven’t asked that we “/unresolve” the issue, we’ll close this out. If you believe further discussion is needed, please add a comment “/unresolve” to reopen the issue.