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

Unable to traverse a TermSet term tree more than 2 levels deep with code in documentation #850

Closed
1 task done
IvanTheBearable opened this issue May 15, 2022 · 3 comments
Assignees
Labels
area: model 📐 Related to the core SDK models bug Something isn't working

Comments

@IvanTheBearable
Copy link

Category

  • Bug

Describe the bug

Using the sample code from the documentation to traverse a TermSet, an exception is produced if you attempt to go more than 2 levels deep.

The exception is:

PnP.Core.MicrosoftGraphServiceException: 404Code: itemNotFoundMessage: Term with id 96bd5df3-b4a9-490b-8a4a-796e9d15177b not found

Where the id is the id of the term who's children I am trying to load.

Steps to reproduce

  1. Configure a term set with a term tree depth of more than two
  2. Use this is the code from the documentation, modified to go one level deeper (plus a few extra try/catches):
var termSet = await termGroup.Sets.GetByIdAsync(spField.TermSetId.ToString());

await termSet.LoadAsync(p => p.Terms);
foreach (var term in termSet.Terms.AsRequested())
{
    // Load the child terms of this term
    try
    {
        await term.LoadAsync(p => p.Terms);
        foreach (var childTerm in term.Terms.AsRequested())
        {
            try
            {
                // New load to get the grandchildren
                await childTerm.LoadAsync(p => p.Terms);
                foreach (var grandchildTerm in childTerm.Terms.AsRequested())
                {
                    // Do something with the term
                    ;
                }
                // Do something with the term
            }
            catch
            {
                ;
            }
        }
    }
    catch
    {
        ;
    }
    // Do something with the term
}

This line:

await childTerm.LoadAsync(p => p.Terms);

fails every time, with the above exception, regardless of whether childTerm actually has children or not.

Expected behavior

Using the sample code from the documentation to traverse a TermSet, I expect to be able to traverse a nested term set for as many levels as it goes.

Environment details (development & target environment)

  • SDK version: [ 1.6.0 ]
  • OS: [Windows 10]
  • SDK used in: [ Function app ]
  • Framework: [ .NET Core v3.1 ]
  • Browser(s): [ N/A ]
  • Tooling: [ Visual Studio 2022 ]

Additional context

There is a workaround. If I re-load the child term using this:

ITerm childTerm2 = await termSet.Terms.GetByIdAsync(childTerm.Id);

I can then get its child terms with:

await childTerm2.LoadAsync(p => p.Terms);
@jansenbe jansenbe added question Further information is requested area: model 📐 Related to the core SDK models labels May 16, 2022
@jansenbe jansenbe self-assigned this May 16, 2022
@jansenbe
Copy link
Contributor

Thanks for reporting this @IvanTheBearable , I'm able to reproduce this issue and will work on a fix.

@jansenbe jansenbe added bug Something isn't working and removed question Further information is requested labels May 16, 2022
jansenbe added a commit that referenced this issue May 16, 2022
@jansenbe
Copy link
Contributor

@IvanTheBearable : fix has been added, will be part of nightly build 1.6.49 or higher. Closing the issue here, feel free to re-open or create a new one if the fix is not helping.

@aaronmorgan
Copy link

Just hit this myself, thanks for the great write up @IvanTheBearable and thanks for the prompt fix @jansenbe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: model 📐 Related to the core SDK models bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants