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

AddLabelAndDescription of a Term throws "PnP.Core.ClientException: Property Id was not yet loaded" #1189

Closed
1 task done
JuergenRB opened this issue May 24, 2023 · 5 comments
Assignees
Labels
area: model 📐 Related to the core SDK models bug Something isn't working

Comments

@JuergenRB
Copy link

Category

  • Bug

Describe the bug

When trying to set the label for an existing term, an error occurs.

PnP.Core.ClientError
PnP.Core.ClientException: Property Id was not yet loaded
   at PnP.Core.Model.TransientObject.GetValue[T](String propertyName)
   at PnP.Core.Model.SharePoint.TermSet.get_Id()
   at PnP.Core.Model.SharePoint.Term.OverrideUpdateOrDeleteApiCall(ApiCallRequest apiCallRequest)
   at PnP.Core.Model.SharePoint.Term.<.ctor>b__2_4(ApiCallRequest apiCallRequest)
   at PnP.Core.Services.QueryClient.BuildUpdateAPICallGraphAsync[TModel](BaseDataModel`1 model, EntityInfo entity, Boolean viaBatchMethod)
   at PnP.Core.Services.QueryClient.BuildUpdateAPICallAsync[TModel](BaseDataModel`1 model, EntityInfo entity, Boolean viaBatchMethod)
   at PnP.Core.Model.BaseDataModel`1.BaseUpdate(Func`2 fromJsonCasting, Action`1 postMappingJson)
   at PnP.Core.Model.BaseDataModel`1.UpdateAsync()

Steps to reproduce

Proceed as described in the documentation

var newTerm = await termStore.GetTermByIdAsync(termSetId, termId, t => t.Labels, t => t.Id);
// Add a new term label for language fr-FR
// Note: fr-FR must be a language allowed in the term store
newTerm.AddLabelAndDescription("French label", "fr-FR");
await newTerm.UpdateAsync();

Expected behavior

Updates the label without error

@jansenbe jansenbe self-assigned this May 25, 2023
@jansenbe jansenbe added question Further information is requested area: model 📐 Related to the core SDK models bug Something isn't working and removed question Further information is requested labels May 25, 2023
@jansenbe
Copy link
Contributor

@JuergenRB : this indeed fails, it's however a harder problem to tackle. In short when using this method the underlying graph call gets a term, but there's no information about it's parent. When it's a top level term the termset of the term can be requested, but when it's a child term the term's parent is another term and in Graph there's no support for getting the parent of a term. I'm evaluating whether I can plug-in a CSOM call (as there's a Term.Parent in CSOM) to workaround.

A workaround for now can be to load the term by traversing the termset

@JuergenRB
Copy link
Author

Thanks for your effort, I am curious about the final implementation.
And thanks for the tip, I will test it with the traversing.

jansenbe added a commit that referenced this issue May 26, 2023
…properties needed to enable operations on the loaded term #1189
@jansenbe
Copy link
Contributor

@JuergenRB : a fix has been pushed, you can try this with the next nightly. Closing this issue now, please re-open or create a new one in case things still don't work for you.

@JuergenRB
Copy link
Author

@jansenbe: I was able to test now with nightly 1.9.68 - I get a different error for the GetTermByIdAsync method

image

I just find it strange, because in my code the DefaultLanguage was definitely loaded for the TermStore.
And it happens with SubTerms (2 Level Term of a TermSet): Group > TermSet > Term > (Sub-)Term

The 1 Level childs of TermSets do not have the issue.

@jansenbe jansenbe reopened this Jun 13, 2023
@jansenbe
Copy link
Contributor

@JuergenRB : the DefaultLanguage property was used in a place while it was not sure it was loaded, so I've added an context.TermStore.EnsurePropertiesAsync(p => p.DefaultLanguage); line. However, if you've loaded DefaultLanguage for the context you are using this error should not happen. So try again with next nightly or alternatively ensure you've loaded the TermStore.DefaultLanguage before calling GetTermById.

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

2 participants