microsoftgraph / msgraph-sdk-go

Microsoft Graph SDK for Go
https://docs.microsoft.com/en-us/graph/sdks/sdks-overview
MIT License
245 stars 38 forks source link

When paginating over groups, some groups are skipped when specifying an OrderBy Clause #784

Closed matt-tyler-qoria closed 1 week ago

matt-tyler-qoria commented 1 month ago

Describe the bug

I attempted to paginate over a very large number of groups using an iterator.

e.g.

func MakeGroupIterator(ctx context.Context, client *msgraphsdk.GraphServiceClient) (Iterator[*models.Group], error) {
    result, err := client.Groups().Get(ctx, &groups.GroupsRequestBuilderGetRequestConfiguration{
        QueryParameters: &groups.GroupsRequestBuilderGetQueryParameters{
            Orderby: []string{"displayName"},
            Select:  []string{"displayName", "description", "id", "objectId", "visibility"},
        },
    })
    if err != nil {
        return nil, err
    }

    it, err := msgraphcore.NewPageIterator[*models.Group](result, client.GetAdapter(), models.CreateGroupCollectionResponseFromDiscriminatorValue)
    if err != nil {
        return nil, err
    }
    return it.Iterate, nil
}

However, I've noticed its not functioning correctly when ordering by display name. It skips over entire ranges and as such there are groups missing from the complete collection - as if its using the last ID to fetch a page, as opposed to the displayName.

If I do not specify the Orderby parameter, everything works correctly.

The entire collection consists of approximately 260,000 groups. When using Orderby, there were roughly 30,000 groups missing.

I'm unsure as to whether this is an issue with the SDK, or with the graph service itself.

I could this being perfectly reasonably behaviour but I was unable to find it documented anywhere.

Expected behavior

All groups are returned via pagination, regardless of the orderby clause

OR

there is some warning somewhere that pagination does not function correctly when specifying an orderby clause.

How to reproduce

Paginate over a group set as above.

I'm unsure as to level of the data that would be required for this to be noticeable.

SDK Version

v1.43.0

Latest version known to work for scenario above?

No response

Known Workarounds

Do not specify an orderby clause when attempting to paginate through a full set of groups.

Debug output

NA

Configuration

Mac OS / ARM 64 Debian x64

Other information

No response

rkodev commented 3 weeks ago

Hi @matt-tyler-qoria , Thanks for trying out the GO SDK. This looks like a service layer issue and not an SDK issue, the SDK uses an endpoint returned by the service, as seen here, to iterate over the pages.

For now, I'd suggests fetching the collection locally and sorting them after fetching them, also could you kindly report this bug here on Microsoft QnA so the relevant team can address is

microsoft-github-policy-service[bot] commented 2 weeks ago

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.