Skip to content

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

@IvanTheBearable

Description

@IvanTheBearable

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);

Metadata

Metadata

Assignees

Labels

area: model 📐Related to the core SDK modelsbugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions