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

InvalidContinuationToken when paginating results with azure-mgmt-compute

Open hussam-Tanium opened this issue 4 years ago • 17 comments

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 19:10 hussam-Tanium

Hey, @hussam-Tanium. Thanks for reporting the issue regarding the new release. I'll tag some folks who can help, and we'll get back to you as soon as possible.

pvaneck avatar Oct 03 '22 20:10 pvaneck

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

ghost avatar Oct 03 '22 20:10 ghost

Are these generated using a different version of autorest than the 27.x packages? I see that in the newer packages, when paginating the new request is genreated by constructing HttpRequest directly, whereas in the 27.x packages the next request is generated with another call to build_xxx_request(). If I manually edit one of the list operations to do it the former way (calling build_xxx_request() again and passing template_url=next_link), it starts working.

jazelenk avatar Oct 07 '22 20:10 jazelenk

Speculation: this autorest change https://github.com/Azure/autorest.python/pull/1307 may be related. It seems that the skiptoken escaping is getting mangled going through the new path.

jazelenk avatar Oct 07 '22 21:10 jazelenk

Thanks for your feedback and we will investigate it asap. Updated: it is a little harder for us to reproduce the error since we don't have so many vm resources to trigger the paging operation. Could you help to confirm which version works well in this scenario? @hussam-Tanium

msyyc avatar Oct 10 '22 03:10 msyyc

You might try a trivial resource type that doesn't consume quota, or consumes quota that is easily raised, such as capacity reservation group, dedicated host group, shared image gallery definition. I'm hitting this listing gallery image versions under a gallery image definition. Those are slow to create however.

jazelenk avatar Oct 10 '22 12:10 jazelenk

Hello @msyyc , the last working version is 27.2.0

hussam-Tanium avatar Oct 11 '22 21:10 hussam-Tanium

Hello @msyyc , the last working version is 27.2.0

Thanks! It is huge help for us and I will compare the two version to find root cause.

msyyc avatar Oct 12 '22 00:10 msyyc

Hi @hussam-Tanium Here is non-work code in 28.0.1: https://github.com/Azure/azure-sdk-for-python/blob/e3415c47d576d2c8f790d73854aa56cda82a9ffa/sdk/compute/azure-mgmt-compute/azure/mgmt/compute/v2022_03_01/operations/_virtual_machines_operations.py#L2236-L2244 Here is work code in 27.2.0: https://github.com/Azure/azure-sdk-for-python/blob/1486a398c39cf9e2f1b7aa938a3e7e52f55fd6e1/sdk/compute/azure-mgmt-compute/azure/mgmt/compute/v2022_03_01/operations/_virtual_machines_operations.py#L2275-L2287

Since list_all has no extra input parameters, this part only add api-version at end of next_link returned by service. After looking into the code, I don't find the root cause. In view of that I can't reproduce the error locally, could you help provide the next_link value for us to debug? (please hide the sensitive info)

msyyc avatar Oct 12 '22 05:10 msyyc

@msyyc - I sent you e-mail with a local repro.

jazelenk avatar Oct 12 '22 11:10 jazelenk

@msyyc I have also sent you an email with the next_link value

hussam-Tanium avatar Oct 12 '22 12:10 hussam-Tanium

Hi @hussam-Tanium I find the error may be caused by urlencode and we fixed it: https://github.com/Azure/autorest.python/pull/1504. Could you help try the fixed private package? Once it works well, we will release a public version.

msyyc avatar Oct 13 '22 12:10 msyyc

Hello @msyyc I will test it now

hussam-Tanium avatar Oct 13 '22 12:10 hussam-Tanium

Hello @msyyc I have confirmed that the package is working properly.

hussam-Tanium avatar Oct 13 '22 12:10 hussam-Tanium

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

msyyc avatar Oct 14 '22 02:10 msyyc

Hi @hussam-Tanium. 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 Oct 14 '22 02:10 ghost

Hi @hussam-Tanium, 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.

ghost avatar Oct 21 '22 04:10 ghost