pnp / PnP-Sites-Core

Microsoft 365 Dev PnP Core component (.NET) targeted for increasing developer productivity with CSOM based solutions.
Other
415 stars 642 forks source link

Provisioning Engine - Exception using resources for TermSet name #617

Open TVDKoni opened 8 years ago

TVDKoni commented 8 years ago

PnP Sites Core - https://github.com/OfficeDev/PnP-Sites-Core [X ] Bug [X ] Office 365 / SharePoint Online

Working with dev branch: SHA-1: fc7289c3b81e83ffea741a497fa8188fd40ff692

Template: http://pastebin.com/vpNfvp0k Resource: http://pastebin.com/ie7SaANb

I like to use a resource file to specify the TermSet name in different languages. A second run with same templates gives following error message:

01/05 - Regional Settings 02/05 - Supported UI Languages 03/05 - Term Groups A unhandeled exception occured: Microsoft.SharePoint.Client.ServerException: A term set already exists with the name specified. at Microsoft.SharePoint.Client.ClientRequest.ProcessResponseStream(Stream responseStream) at Microsoft.SharePoint.Client.ClientRequest.ProcessResponse() at Microsoft.SharePoint.Client.ClientRequest.ExecuteQueryToServer(ChunkStringBuilder sb) at Microsoft.SharePoint.Client.ClientRequest.ExecuteQuery() at Microsoft.SharePoint.Client.ClientRuntimeContext.ExecuteQuery() at Microsoft.SharePoint.Client.ClientContext.ExecuteQuery() at Microsoft.SharePoint.Client.ClientContextExtensions.ExecuteQueryImplementation(ClientRuntimeContext clientContext, Int32 retryCount, Int32 delay) in C:\Data\Source\github.com\TrivadisCloud\PnP-Sites-Core\Core\OfficeDevPnP.Core\AppModelExtensions\ClientContextExtensions.cs:line 80 at Microsoft.SharePoint.Client.ClientContextExtensions.ExecuteQueryRetry(ClientRuntimeContext clientContext, Int32 retryCount, Int32 delay) in C:\Data\Source\github.com\TrivadisCloud\PnP-Sites-Core\Core\OfficeDevPnP.Core\AppModelExtensions\ClientContextExtensions.cs:line 39 at OfficeDevPnP.Core.Framework.Provisioning.ObjectHandlers.ObjectTermGroups.ProvisionObjects(Web web, ProvisioningTemplate template, TokenParser parser, ProvisioningTemplateApplyingInformation applyingInformation) in C:\Data\Source\github.com\TrivadisCloud\PnP-Sites-Core\Core\OfficeDevPnP.Core\Framework\Provisioning\ObjectHandlers\ObjectTermGroups.cs:line 113 at OfficeDevPnP.Core.Framework.Provisioning.ObjectHandlers.SiteToTemplateConversion.ApplyRemoteTemplate(Web web, ProvisioningTemplate template, ProvisioningTemplateApplyingInformation provisioningInfo) in C:\Data\Source\github.com\TrivadisCloud\PnP-Sites-Core\Core\OfficeDevPnP.Core\Framework\Provisioning\ObjectHandlers\SiteToTemplateConversion.cs:line 220 at Microsoft.SharePoint.Client.WebExtensions.ApplyProvisioningTemplate(Web web, ProvisioningTemplate template, ProvisioningTemplateApplyingInformation applyingInformation) in C:\Data\Source\github.com\TrivadisCloud\PnP-Sites-Core\Core\OfficeDevPnP.Core\AppModelExtensions\WebExtensions.cs:line 1082 at Provisioning.CLI.Console.Program.ApplyTemplate(Parser parser, FileInfo inFile, String tourl) in C:\Data\Source\github.com\TrivadisCloud\PnP\Samples\Provisioning.CLI\Provisioning.CLI.Console\Program.cs:line 315 at Provisioning.CLI.Console.Program.Main(String[] args) in C:\Data\Source\github.com\TrivadisCloud\PnP\Samples\Provisioning.CLI\Provisioning.CLI.Console\Program.cs:line 154

PaoloPia commented 7 years ago

Isn't this almost the same issue as #616? I will close this item and keep the original one open. Thanks.

jansenbe commented 7 years ago

Internal testing feedback: Provisioned user provided template (term group and term sets) in site collection successfully in first run. If we provision second time getting below error. “A term set already exists with the name specified.”

Provisioned user provided template and getting below error as mentioned by user. The field was found invalid: {termsetid:Site Collection - tenant.sharepoint.com-sites-siteUrl:Trivadis Document Group}

Johesmil commented 7 years ago

Just wanted to bump this issue and point to the spot that seems to be the cause: ObjectTermGroups.cs#L140

If you follow the flow, you can see that the check to see if the term set exists (lines 145-147) is made using the normalizedTermSetName, but NOT the parsed name.

var normalizedTermSetName = TaxonomyItem.NormalizeName(web.Context, modelTermSet.Name);
web.Context.ExecuteQueryRetry();

if (!newGroup)
{
    set =
        group.TermSets.FirstOrDefault(
            ts => ts.Id == modelTermSet.Id || ts.Name == normalizedTermSetName.Value);
}
if (set == null)
{
    if (modelTermSet.Id == Guid.Empty)
    {
        modelTermSet.Id = Guid.NewGuid();
    }
    set = group.CreateTermSet(parser.ParseString(modelTermSet.Name), modelTermSet.Id,
        modelTermSet.Language ?? termStore.DefaultLanguage);

This means the token is being compared rather than the value it represents. It will therefore try to create a new term set.

Props to @johannesekstrand for finding the source of the issue.