question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue
  • 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, https://github.com/Azure/azure-sdk-for-python/blob/447e6f766ac809b95bac65e72752c44a59ea073f/sdk/policyinsights/azure-mgmt-policyinsights/azure/mgmt/policyinsights/operations/_policy_states_operations.py#L139

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.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
00Kai0commented, 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

0reactions
msftbot[bot]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!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Not able to iterate through QuerySet results with Django
I'm not sure exactly how to get at each Query set that is inside a larger query set. It's all kind of confusing...
Read more >
Unable to iterate over a database ResultSet twice · Issue #2532
When you try to iterate over a result set a second time, you get an exception: This result is a forward only result...
Read more >
LWC: How to iterate over a list of SObjects
I have used the array in JS and lloped the result to convert the map into a list for template iteration. Component: <template>...
Read more >
Iterate over a list in Python - GeeksforGeeks
Let's see all the different ways to iterate over a list in Python, and performance comparison between them. Method #1: Using For loop....
Read more >
Item 54: Know How to Iterate Over Objects - Effective TypeScript
Iterating over the keys and values in an object is a common operation that's ... The difficulty results from a combination of the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found