databricks-sdk-go icon indicating copy to clipboard operation
databricks-sdk-go copied to clipboard

[ISSUE] `workspaceClient.Users.ListAll` is doing an additional API call even if `TotalResults` is specified and the number of returned users matches it

Open alexott opened this issue 1 year ago • 2 comments

Description

workspaceClient.Users.ListAll is doing an additional API call even if TotalResults is specified and the number of returned users matches it.

Reproduction

In Terraform exporter I'm returning following answer to the ListAll API call:

	userListIdUsernameFixture = qa.HTTPFixture{
		Method:   "GET",
		Resource: "/api/2.0/preview/scim/v2/Users?attributes=id%2CuserName&count=100&startIndex=1",
		Response: iam.ListUsersResponse{
			Resources: []iam.User{
				{
					Id:       "id",
					UserName: "[email protected]",
				},
			},
			TotalResults: 1,
			StartIndex:   1,
		},
		ReuseRequest: true,
	}

But even if the number of resources matches to TotalResults, I'm still need to add a fixture with empty results:

	userListIdUsernameFixture2 = qa.HTTPFixture{
		Method:   "GET",
		Resource: "/api/2.0/preview/scim/v2/Users?attributes=id%2CuserName&count=100&startIndex=2",
		Response: iam.ListUsersResponse{
			Resources:    []iam.User{},
			TotalResults: 1,
			StartIndex:   2,
		},
		ReuseRequest: true,
	}

Expected behavior

An additional API call isn't required

Is it a regression?

No

Other Information

  • OS: [e.g. macOS]
  • Version: 0.26.1

Additional context

Was need to modify PR after upgrade of SDK: https://github.com/databricks/terraform-provider-databricks/pull/2980

alexott avatar Dec 09 '23 14:12 alexott

Yup, this is a good point. We can add an extra check to skip the last request in this case.

mgyucht avatar Jan 03 '24 10:01 mgyucht

I think that it's applicable to most of the list APIs

alexott avatar Jan 03 '24 10:01 alexott