Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to iterate over the entire results of policy_states.list_query_results_for_subscription. #17280

Closed
ietashish opened this issue Mar 11, 2021 · 7 comments
Assignees
Labels
bug This issue requires a change to an existing behavior in the product in order to be resolved. customer-reported Issues that are reported by GitHub users external to the Azure organization. Mgmt This issue is related to a management-plane library. needs-author-feedback Workflow: More information is needed from author to address the issue. no-recent-activity There has been no recent activity on this issue. Policy Insights Service Attention Workflow: This issue is responsible by Azure service team.

Comments

@ietashish
Copy link

  • Package Name: azure.mgmt.policyinsights
  • Package Version: 1.0.0
  • Operating System: MacOS
  • Python Version: 3.7

Describe the bug
The issue happens when trying to list the policy state of entire subscription.

After instantiating PolicyInsightsClient and iterating over the results returned by client.policy_states.list_query_results_for_subscription(...), the following exception is thrown

 File "/Users/ashishg/****/venv/lib/python3.7/site-packages/azure/mgmt/policyinsights/operations/_policy_states_operations.py", line 352, in get_next
    raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat)
azure.core.exceptions.HttpResponseError: (HttpMethodNotSupported) The http method 'GET' is not supported for 'queryResults'.

Only the first 1000 policy state results are listed and when the client goes on to fetch the next 1000 results it errors out with the above exception.

The issue is happening because the Policy States List API (https://docs.microsoft.com/en-us/rest/api/policy/policystates/listqueryresultsforsubscription) expects the URL returned by @odata.nextLink attribute to be called over POST and not GET.

The problem seems to in line,

Things start to work, on changing the line from request = self._client.get(url, query_parameters, header_parameters)
to
request = self._client.post(url, query_parameters, header_parameters)

To Reproduce
Steps to reproduce the behavior:

  1. pip install azure-mgmt-policyinsights (latest version which is 1.0.0)
  2. Run the following simple snippet to reproduce the issue.
    NOTE: Make sure that the subscription this is tried upon has more than 1000 policy state results.
from azure.mgmt.policyinsights._policy_insights_client import PolicyInsightsClient

#credential = <Create the credential object here>
#sub_id = <some subscription id>

client = PolicyInsightsClient(cred, base_url=mavlink_helpers.get_arm_base_url(tenant_region), subscription_id=sub_id)
policy_states = client.policy_states.list_query_results_for_subscription(policy_states_resource="latest",
                                                                             subscription_id=sub_id)
for policy_state in policy_states:
    policy_state = policy_state.as_dict()
    print(policy_state['policy_definition_id'], policy_state['resource_id'])

Expected behavior
One should be able to iterate over the entire list of policy states.

@ghost ghost added needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Mar 11, 2021
@yunhaoling yunhaoling added Mgmt This issue is related to a management-plane library. Policy Insights labels Mar 11, 2021
@ghost ghost removed the needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. label Mar 11, 2021
@yunhaoling yunhaoling added bug This issue requires a change to an existing behavior in the product in order to be resolved. and removed question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Mar 11, 2021
@yunhaoling
Copy link
Contributor

thanks for the feedback! we'll investigate this asap.
looping in @msyyc who could provide further help on mgmt libraries.

@msyyc msyyc assigned 00Kai0 and unassigned msyyc Mar 12, 2021
@msyyc
Copy link
Member

msyyc commented Mar 12, 2021

@00Kai0 please provide help on the issue

@00Kai0
Copy link
Contributor

00Kai0 commented Mar 18, 2021

This issue happened because next link using wrong method.
Normally, next_link will use get to get next page. But this API uses an unusual post request to get data.
https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/operations/_policy_states_operations.py#L139

@ghost
Copy link

ghost commented Apr 13, 2021

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @kenieva.

Issue Details
  • Package Name: azure.mgmt.policyinsights
  • Package Version: 1.0.0
  • Operating System: MacOS
  • Python Version: 3.7

Describe the bug
The issue happens when trying to list the policy state of entire subscription.

After instantiating PolicyInsightsClient and iterating over the results returned by client.policy_states.list_query_results_for_subscription(...), the following exception is thrown

 File "/Users/ashishg/****/venv/lib/python3.7/site-packages/azure/mgmt/policyinsights/operations/_policy_states_operations.py", line 352, in get_next
    raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat)
azure.core.exceptions.HttpResponseError: (HttpMethodNotSupported) The http method 'GET' is not supported for 'queryResults'.

Only the first 1000 policy state results are listed and when the client goes on to fetch the next 1000 results it errors out with the above exception.

The issue is happening because the Policy States List API (https://docs.microsoft.com/en-us/rest/api/policy/policystates/listqueryresultsforsubscription) expects the URL returned by @odata.nextLink attribute to be called over POST and not GET.

The problem seems to in line,

Things start to work, on changing the line from request = self._client.get(url, query_parameters, header_parameters)
to
request = self._client.post(url, query_parameters, header_parameters)

To Reproduce
Steps to reproduce the behavior:

  1. pip install azure-mgmt-policyinsights (latest version which is 1.0.0)
  2. Run the following simple snippet to reproduce the issue.
    NOTE: Make sure that the subscription this is tried upon has more than 1000 policy state results.
from azure.mgmt.policyinsights._policy_insights_client import PolicyInsightsClient

#credential = <Create the credential object here>
#sub_id = <some subscription id>

client = PolicyInsightsClient(cred, base_url=mavlink_helpers.get_arm_base_url(tenant_region), subscription_id=sub_id)
policy_states = client.policy_states.list_query_results_for_subscription(policy_states_resource="latest",
                                                                             subscription_id=sub_id)
for policy_state in policy_states:
    policy_state = policy_state.as_dict()
    print(policy_state['policy_definition_id'], policy_state['resource_id'])

Expected behavior
One should be able to iterate over the entire list of policy states.

Author: ietashish
Assignees: 00Kai0, zhangyan133
Labels:

Mgmt, Policy Insights, Service Attention, bug, customer-reported

Milestone: -

@msyyc
Copy link
Member

msyyc commented Apr 28, 2021

Fix swagger PR :Azure/azure-rest-api-specs#14035

@SaurabhSharma-MSFT
Copy link
Member

@ietashish I am following to know if your issue is resolved ? Please let us know.

@SaurabhSharma-MSFT SaurabhSharma-MSFT added the needs-author-feedback Workflow: More information is needed from author to address the issue. label Nov 15, 2021
@ghost ghost added the no-recent-activity There has been no recent activity on this issue. label Nov 23, 2021
@ghost
Copy link

ghost commented Nov 23, 2021

Hi, we're sending this friendly reminder because we haven't heard back from you in a while. We need more information about this issue to help address it. Please be sure to give us your input within the next 7 days. If we don't hear back from you within 14 days of this comment the issue will be automatically closed. Thank you!

@ghost ghost closed this as completed Dec 7, 2021
openapi-sdkautomation bot pushed a commit to AzureSDKAutomation/azure-sdk-for-python that referenced this issue Feb 25, 2022
New API spec for peering microsoft.peering 2022 01 01 (Azure#17280)

* Adding 2022-01-01 version for Peering

* update Peering spec for 2022-01-01

* updating 2022-01-01 Peering spec

* update swagger examples

* Adds base for updating Microsoft.Peering from version stable/2021-06-01 to version 2022-01-01

* Updates readme

* Updates API version in new specs and examples

* Creating new API spec version 2022-01-01 for Peering

* Fix staging lint issues

* update as per comment - updating x-ms-enum names

Co-authored-by: Sridharan J <srij@microsoft.com>
@github-actions github-actions bot locked and limited conversation to collaborators Apr 12, 2023
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue requires a change to an existing behavior in the product in order to be resolved. customer-reported Issues that are reported by GitHub users external to the Azure organization. Mgmt This issue is related to a management-plane library. needs-author-feedback Workflow: More information is needed from author to address the issue. no-recent-activity There has been no recent activity on this issue. Policy Insights Service Attention Workflow: This issue is responsible by Azure service team.
Projects
None yet
Development

No branches or pull requests

7 participants