Azure-sdk-for-go: List Tenants returns nil for DisplayName & Domains instead of its actual values

Created on 14 Jul 2020  路  12Comments  路  Source: Azure/azure-sdk-for-go

Bug Report

  • import path of package in question
    services/resources/mgmt/2019-11-01/subscriptions/

  • SDK version
    44.0.0

    • Specify the exact commit if possible;
      github.com/Azure/azure-sdk-for-go ^44.0.0 v44.0.0 c536f2d v44.0.0 15
      github.com/Azure/go-autorest ^14.0.0 v14.1.1 778ae56 v14.2.0 10
  • output of go version
    go version go1.14 darwin/amd64

In detail:
So, I am doing the following:

tenantList, err := client.List(context.Background())

This returns an array of tenants in tenantList.Values()

When I go over the array, I see that for the tenant, only tenantID and ID are populated and not the Domain and DisplayName as mentioned here: https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2019-11-01/subscriptions?tab=doc#TenantIDDescription

  • What happened?

Not getting Domain & DisplayName

  • What did you expect or want to happen?

I should have received it in the response as I see it here: https://docs.microsoft.com/en-us/rest/api/resources/tenants/list

  • How can we reproduce it?

Create a New Tenants Client as follows:

`client := subscriptions.NewTenantsClient()
client.Authorizer = sess.Authorizer

and then do the tenantList, err := client.List(context.Background()) and go over the tenants list`

Here's a tenant: {0xc001cf43f0 0xc001cd6a00 Home <nil> <nil> <nil> <nil>}

As you can see except the TenantCategory (Home), Id & TenantId, everything else is set to nil which should not be the case.

  • Anything we should know about your environment.
    Nothing special about the environment.
AAD Mgmt Service Attention customer-reported question

All 12 comments

Hi @rushabh268 thanks for this issue!

Usually the List API returns a result with pagination, which means only call tenantList.Values() may not get the full result, you have to check if there is a next page. You can use the function tenantList.NextWithContext(ctx) to move to next page, and so on. By accumulating all the results in every page, you would get your full list of the results.
In some circumstances, the service may return an empty page but in the same time tells you that there is a next page. I assume you hit this particular circumstance.
Usually I would recommend you to switch to use the ListComplete function which will return an iterator for you. You can use the iterator to easily iterate over the whole result without considering about paging. But unfortunately we have a known issue on this circumstance when service returns an empty page with a valid next page. (see this issue). We are very close to fixing this, stay tuned.

Thanks!

@ArcturusZhang Thank you for the quick response. I tried ListComplete as well but my problem is different. I understand the issue with pagination. My issue is - I have a single tenant in a subscription - It is not returning the DisplayName & Domains for that tenant. I get the TenantId, TenantCategory and Id but not the DisplayName & Domains using the Golang SDK.

I tried the REST API (https://docs.microsoft.com/en-us/rest/api/resources/tenants/list) for my subscription and I get all the attributes for the same tenant, even the Domains & the DisplayName so the error is in this SDK which is not populating the entire response from the server.

I see. Could you please make some log of the SDK and posted here?
You can enable logging referring to this by exporting an environment variable AZURE_GO_SDK_LOG_LEVEL=DEBUG

@ArcturusZhang Here's the log from the SDK request:

```(2020-07-14T20:53:13.8397820-07:00) INFO: REQUEST: GET https://management.azure.com/tenants?api-version=2019-11-01
User-Agent: Go/go1.14 (amd64-darwin) go-autorest/v14.1.1 Azure-SDK-For-Go/v44.0.0 subscriptions/2019-11-01
Authorization: REDACTED
(2020-07-14T20:53:13.8992560-07:00) INFO: RESPONSE: 200 https://management.azure.com/tenants?api-version=2019-11-01
X-Ms-Ratelimit-Remaining-Tenant-Reads: 11999
X-Ms-Routing-Request-Id: WESTUS:20200715T035313Z:41d1e975-c087-4c8726-a1ac-8d85048a2255
X-Content-Type-Options: nosniff
Date: Wed, 15 Jul 2020 03:53:12 GMT
Cache-Control: no-cache
Pragma: no-cache
Vary: Accept-Encoding
X-Ms-Request-Id: 41d1e6534-c087-4e96-a1ac-8d85048a2255
X-Ms-Correlation-Request-Id: 41d1e6534-c087-4e96-a1ac-8d85048a2255
Strict-Transport-Security: max-age=31536000; includeSubDomains
Content-Type: application/json; charset=utf-8
Expires: -1
{"value":[{"id":"/tenants/86433ebd-6dc6-4419-ad7f-efd45645aced","tenantId":"86433ebd-6dc6-4419-ad7f-efd45645aced","tenantCategory":"Home"}]}

As you can see above, there is no Domain or DisplayName attribute set in the response even when it should be as documented here: https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2019-11-01/subscriptions?tab=doc#TenantIDDescription

Well, based on the given response, it is unlikely caused by the SDK itself, since the service never returns them in the response. Therefore the SDK surely cannot get them.

I noticed that in the doc you posted, the example is using api-version 2020-01-01. This may be the problem? Let me try with another api-version

Hi @rushabh268 I just tried on the doc page changing the api-version to 2019-11-01, I could properly get the DisplayName and Domains.
Also I wrote this little piece of testing program

func listTenant(authorizer autorest.Authorizer) {
    client := subscriptions.NewTenantsClient()
    client.Authorizer = authorizer
    resp, err := client.List(ctx)
    if err != nil {
        panic(err)
    }
    values := resp.Values()
    b, _ := json.Marshal(values)
    fmt.Println(string(b))
}

Debugging it and get the following output on DisplayName and Domains:
image

Based on the above reproduction and the reason I told in the previous comment, I believe the issues you are encountering should not caused by the SDK but should be something wrong on the environment or the service itself.

Therefore I tagged this issue to see if the service team could give a look at this. Thanks.

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @anuragdalmia, @shilpigautam, @ramaganesan-rg.

Hi @ArcturusZhang Thank you for directing it to the right team. On my Golang SDK, I am using api-version as 2019-11-01 because that's the latest available version of subscriptions package. I doubt the problem is on the service because when I use https://docs.microsoft.com/en-us/rest/api/resources/tenants/list for the same subscription, I see DisplayName & Domains being returned correctly and I confirmed it from the portal as well.

@anuragdalmia, @ShilpiGautam, @ramaganesan-rg Any update on this?

Hi @rushabh268 v45.0.0 has been released with the new changes to the LIST APIs, could you please have a try?

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

Was this page helpful?
0 / 5 - 0 ratings