Azure / azure-sdk-for-python

This repository is for active development of the Azure SDK for Python. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/python/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-python.
MIT License
4.53k stars 2.76k forks source link

[BUG] DnsResolverManagementClient.forwarding_rules.list iterator exception when pages are left #37004

Closed AndreasAugustin closed 1 week ago

AndreasAugustin commented 2 weeks ago

Describe the bug

Exception if rulesets count is greater 100 with ForwardingRulesOperations.list within iterator. (not sure if the exception is also thrown if count is < 100. 100 is default top)

Example code:

from azure.mgmt.dnsresolver import DnsResolverManagementClient
from azure.identity import DefaultAzureCredential

client = DnsResolverManagementClient(credential=DefaultAzureCredential(), subscription_id=subscription_id)

res = client.forwarding_rules.list(
        resource_group_name=<resource_group_name>,
        dns_forwarding_ruleset_name=<ruleset_name>,
        # top = 10,
    )

for i in res:
  print(i.as_dict())

when reaching 100 (or last item within page with top parameter) there is an exception

ValueError('The value provided for the url part \'https://management.azure.com/subscriptions/****/resourceGroups/****/providers/Microsoft.Network/dnsForwardingRulesets/****/forwardingRules?$skipToken=[{"token":"****","range":{"min":"05C1DFFFFFFFFC","max":"FF"}}]&api-version=2022-07-01\' was incorrect, and resulted in an invalid url')

To Reproduce Use the code sample above. Not sure if this happens if you have less then 100 rules (not tested)

Expected behavior No exception

Additional context Possibly somehow related to #29940 (but the mentioned workaround is not working in our case).

stack trace

KeyError: '"token"'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/site/wwwroot/svc_azure.py", line 130, in list_dns_ruleset_with_rules
    for i in az_res:
  File "/home/site/wwwroot/.python_packages/lib/site-packages/azure/core/paging.py", line 123, in __next__
    return next(self._page_iterator)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/site/wwwroot/.python_packages/lib/site-packages/azure/core/paging.py", line 75, in __next__
    self._response = self._get_next(self.continuation_token)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/site/wwwroot/.python_packages/lib/site-packages/azure/mgmt/dnsresolver/operations/_forwarding_rules_operations.py", line 821, in get_next
    request = prepare_request(next_link)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/site/wwwroot/.python_packages/lib/site-packages/azure/mgmt/dnsresolver/operations/_forwarding_rules_operations.py", line 809, in prepare_request
    request.url = self._client.format_url(request.url)  # type: ignore
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/site/wwwroot/.python_packages/lib/site-packages/azure/core/pipeline/transport/_base.py", line 658, in format_url
    url = _format_url_section(url_template, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/site/wwwroot/.python_packages/lib/site-packages/azure/core/pipeline/transport/_base.py", line 108, in _format_url_section
    raise ValueError(****
xiangyan99 commented 2 weeks ago

Thanks for the feedback, we’ll investigate asap.

msyyc commented 2 weeks ago

@ChenxiJiang333 Please help on this issue.

ChenxiJiang333 commented 2 weeks ago

got it

ChenxiJiang333 commented 1 week ago

Hi @AndreasAugustin, I guess you're using the package azure-mgmt-dnsresolver with version 1.0.0, could you try update it to azure-mgmt-dnsresolver==1.1.0b1?

AndreasAugustin commented 1 week ago

Hi @AndreasAugustin, I guess you're using the package azure-mgmt-dnsresolver with version 1.0.0, could you try update it to azure-mgmt-dnsresolver==1.1.0b1?

Hi @ChenxiJiang333 . Yes azure-mgmt-dnsresolver with version 1.0.0 (sorry had the wrong package name and version within the description -> changed).

Ran some of my tests with version 1.1.0b1 -> the exception did not occur again and the list of results is also > 100. Seems the version is fixing the bug (at least within my tests).

Thanks

AndreasAugustin commented 1 week ago

@ChenxiJiang333 is there is not a new release available yet (we are using the lib within a production environment). Just a beta. For me this issue is not closed yet. When will the new release be available?

Would be also nice to get a link to the related changes. Thanks

ChenxiJiang333 commented 1 week ago

Hi @AndreasAugustin , the python SDK is generated by swagger definition and azure-mgmt-dnsresolver==1.1.0b1 has been released with latest api version. Since it's an old server, I'm not sure whether service team would launch a new api version and ask for the release of a new SDK version. I suggest you open an issue at https://github.com/Azure/azure-rest-api-specs/issues to get support from the service team.

AndreasAugustin commented 1 week ago

Hi @AndreasAugustin , the python SDK is generated by swagger definition and azure-mgmt-dnsresolver==1.1.0b1 has been released with latest api version. Since it's an old server, I'm not sure whether service team would launch a new api version and ask for the release of a new SDK version. I suggest you open an issue at https://github.com/Azure/azure-rest-api-specs/issues to get support from the service team.

Hi @ChenxiJiang333 and thanks for the clarification. Created an issue as requested: https://github.com/Azure/azure-rest-api-specs/issues/30409