Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception "Detected nextLink loop. Nextlink value: " thrown when Making Delta-Requests with the PageIterator #1948

Closed
Danny4021 opened this issue Jun 6, 2023 · 2 comments · Fixed by microsoftgraph/msgraph-sdk-dotnet-core#679
Assignees
Labels

Comments

@Danny4021
Copy link

Hello,

I'm trying to upgrade the MS Graph SDK from 4.x to 5.11 and encountered the following problem:
I've previously used NextPageRequests to access the next page of a delta request I made but since this features was removed in 5.x I'm trying to use the PageIterator to make Delta-Requests.
I'm creating the PageIterator like this:

DeltaResponse deltaRequest = await  _graphClient
					.Users[mailAddress]
					.MailFolders[folderId]
					.Messages
					.Delta
					.GetAsync();
			
PageIterator<Message, DeltaResponse> iterator = PageIterator<Message, DeltaResponse>.CreatePageIterator(_graphClient, deltaRequest, message => callback.Invoke(message));

When I then call await iterator.IterateAsync() it works the first time without any problems.
Note that I currently don't have any mails in the folder I'm listening to. I'm simply trying to check for changes every x-seconds.
Since the iterator couldn't find any changes, the API returned a DeltaLink and the NextLink is set to string.Empty as seen in the class PageIterator.cs:

Deltalink = deltalink.ToString();
State = PagingState.Delta;
Nextlink = string.Empty;

When I then try to call ResumeAsync() OR IteratorAsync() once more, I get this error message:
Detected nextLink loop. Nextlink value:

I debugged the code to find the code that throws this exception and found this inside the PageIterator.cs class:

// Detect nextLink loop
if (Nextlink.Equals(ExtractNextLinkFromParsable(_currentPage)))
{
    throw new ServiceException($"Detected nextLink loop. Nextlink value: {Nextlink}");
}

Since I don't have any new changes inside the watched folder, the next request made also returns a DeltaLink instead of a NextLink.
But since there is no NextLink inside the the AdditionalData inside of the _currentPage, the method ExtractNextLinkFromParsable returns an empty string, as seen here:

// the next link property may not be defined in the response schema so we also check its presence in the additional data bag
return parsableCollection.AdditionalData.TryGetValue(CoreConstants.OdataInstanceAnnotations.NextLink,out var nextLink) ? nextLink.ToString() : string.Empty;

But this is a problem, because the PageIterator assigned the NextLink to string.Empty in the last request and now this request returns a string.Empty as well, so the PageIterator thinks that I am inside a NextLink loop and throws an exception.
So now my question:
Am I doing something wrong? Am I not supposed to use the PageIterator like this? Is there any better way to check for changes with a Delta-Request? I've tried to follow this microsoft turorial for delta-requests: https://learn.microsoft.com/en-us/graph/delta-query-users?tabs=http
But the QueryParameters don't have a SkipToken or DeltaToken anymore and since the PageIterator has a Delta State I thought I should be able to use it instead.

Thanks in advance

@ghost ghost added the Needs: Triage label Jun 6, 2023
@ghost ghost added this to Issues to triage in Graph SDK - DotNet Jun 6, 2023
@Danny4021
Copy link
Author

Hey,

I just wanted to ask if there is anything new regarding this issue?
Do I need to provide further info? If there's something not clear just point it out and I'll try to explain it.

Thanks

@Nemeczek
Copy link

It is the same in Python SDK. I think currently SkipToken and DeltaToken are not supported at all. And the worst part is that you can't pass arbitrary headers to QueryParameters. Then I could easily do the paging and delta by myself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Graph SDK - DotNet
  
Completed
Development

Successfully merging a pull request may close this issue.

3 participants