azure-sdk-for-python icon indicating copy to clipboard operation
azure-sdk-for-python copied to clipboard

Error With Pagination in ComputeManagementClient in 28.0.0

Open SpencerLN opened this issue 4 years ago • 9 comments

  • Package Name: azure-mgmt-compute
  • Package Version: 28.0.0
  • Operating System: Linux
  • Python Version: 3.10.2

Describe the bug Operations in the ComputeManagementclient that require pagination are failing after upgrading the package to 28.0.0 To Reproduce Steps to reproduce the behavior:

  1. Have a subscription with multiple pages of resources, in my case, VM scalesets
  2. Call list_all():
    subscription_id = subscription.subscription_id
    with ComputeManagementClient(credential, subscription_id) as compute_client:
            list(compute_client.virtual_machine_scale_sets.list_all())

Expected behavior ComputeManagementClient.virtual_machine_scale_sets.list_all() should paginate successfully and return all resources. Screenshots If applicable, add screenshots to help explain your problem.

AttributeError: 'ComputeManagementClientConfiguration' object has no attribute 'api_version'
cannot unpack non-iterable AttributeError object
  File "/code/azure_virtual_machines.py", line 117, in get_azure_virtual_machines
    get_azure_vm_scalesets_for_subscription(subscription))
  File "/code/azure_virtual_machines.py", line 87, in get_azure_vm_scalesets_for_subscription
    for vm_scaleset in compute_client.virtual_machine_scale_sets.list_all():
  File "~/.pyenv/versions/3.10.2/lib/python3.10/site-packages/azure/core/paging.py", line 128, in __next__
    return next(self._page_iterator)
  File "~/.pyenv/versions/3.10.2/lib/python3.10/site-packages/azure/core/paging.py", line 76, in __next__
    self._response = self._get_next(self.continuation_token)
  File "~/.pyenv/versions/3.10.2/lib/python3.10/site-packages/azure/mgmt/compute/v2022_08_01/operations/_virtual_machine_scale_sets_operations.py", line 2173, in get_next
    request = prepare_request(next_link)
  File "~/.pyenv/versions/3.10.2/lib/python3.10/site-packages/azure/mgmt/compute/v2022_08_01/operations/_virtual_machine_scale_sets_operations.py", line 2158, in prepare_request
    _next_request_params["api-version"] = self._config.api_version

Additional context In https://github.com/Azure/azure-sdk-for-python/commit/0405607fa62d965d9c7d5a223196c2c6a6fa1aa9, _next_request_params["api-version"] = self._config.api_version was added in several places, but azure.mgmt.compute._configuration.ComputeManagementClientConfiguration does not have an api_version attribute.

SpencerLN avatar Sep 28 '22 14:09 SpencerLN

Hi @SpencerLN, thank you for opening an issue! The Additional context section is very helpful; thank you for digging into the cause. I'll tag the appropriate folks so we can get back to you as soon as possible.

laiapat avatar Sep 28 '22 18:09 laiapat

Thank you for your feedback. This has been routed to the support team for assistance.

ghost avatar Sep 28 '22 18:09 ghost

I will look into it asap. Thanks!

msyyc avatar Sep 29 '22 07:09 msyyc

Hi @SpencerLN Please try the latest version: https://pypi.org/project/azure-mgmt-compute/28.0.1/

msyyc avatar Sep 30 '22 09:09 msyyc

Hi @SpencerLN. 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.

ghost avatar Sep 30 '22 09:09 ghost

/unresolve Hello @msyyc, after testing 28.0.1, I'm receiving a new error. I verified that I do not receive this error on version 27.2.0.

Package Name: azure-mgmt-compute
Package Version: 28.0.1
Operating System: MacOS 12.6
Python Version: 3.8 and 3.9

Describe the bug Operations in the ComputeManagementclient that require pagination are failing after upgrading the package to 28.0.0 and 28.0.1.

To Reproduce Steps to reproduce the behavior:

1. Have a subscription with multiple pages of resources, in my case, VMs
2. Call `list_all()`
    subscription_id = subscription.subscription_id
    compute_client = ComputeManagementClient(
            credential,
            subscription_id=subscription_id,
            api_version=compute_api_version
        )
        sub_vms = compute_client.virtual_machines.list_all()
        for vm in sub_vms:
            vm_id = vm.vm_id

Expected behavior ComputeManagementClient.virtual_machines.list_all() should paginate successfully and return all resources. Screenshots If applicable, add screenshots to help explain your problem. Python 3.8and API version v2022-03-01

File "/tmp/tmpwe4ln3d0/my_script.py", line 164, in my_method
    for vm in sub_vms:
  File "/tmp/tmpwe4ln3d0/venv/lib/python3.8/site-packages/azure/core/paging.py", line 128, in __next__
    return next(self._page_iterator)
  File "/tmp/tmpwe4ln3d0/venv/lib/python3.8/site-packages/azure/core/paging.py", line 76, in __next__
    self._response = self._get_next(self.continuation_token)
  File "/tmp/tmpwe4ln3d0/venv/lib/python3.8/site-packages/azure/mgmt/compute/v2022_03_01/operations/_virtual_machines_operations.py", line 2263, in get_next
    raise HttpResponseError(response=response, error_format=ARMErrorFormat)
azure.core.exceptions.HttpResponseError: (InvalidContinuationToken) Invalid continuation token in the request uri. Continuation token - 'continuation_token'

Python 3.9 and API version v2022-08-01

File "/Users/hussambteibet/PycharmProjects/zray_modules/modules/cloud_asset_inventory/azure_inventory.py", line 164, in get_subscription_data
    for vm in sub_vms:
  File "/Users/hussambteibet/PycharmProjects/zray_modules/venv/lib/python3.9/site-packages/azure/core/paging.py", line 128, in __next__
    return next(self._page_iterator)
  File "/Users/hussambteibet/PycharmProjects/zray_modules/venv/lib/python3.9/site-packages/azure/core/paging.py", line 76, in __next__
    self._response = self._get_next(self.continuation_token)
  File "/Users/hussambteibet/PycharmProjects/zray_modules/venv/lib/python3.9/site-packages/azure/mgmt/compute/v2022_08_01/operations/_virtual_machines_operations.py", line 2263, in get_next
    raise HttpResponseError(response=response, error_format=ARMErrorFormat)
azure.core.exceptions.HttpResponseError: (InvalidContinuationToken) Invalid continuation token in the request uri. Continuation token - 'continuation_token'.

hussam-Tanium avatar Oct 03 '22 14:10 hussam-Tanium

Hi hussam-Tanium, only the original author of the issue can ask that it be unresolved. Please open a new issue with your scenario and details if you would like to discuss this topic with the team.

ghost avatar Oct 03 '22 14:10 ghost

I am seeing problems with both 28.0.0 and 28.0.1. https://github.com/Azure/azure-sdk-for-python/issues/26604 appears to track this for 28.0.1.

jazelenk avatar Oct 06 '22 21:10 jazelenk

fixed version is released : https://pypi.org/project/azure-mgmt-compute/29.0.0/

msyyc avatar Oct 14 '22 02:10 msyyc