Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Filipe Neves 8 posts 28 karma points
    Mar 26, 2019 @ 19:19
    Filipe Neves
    0

    Content Service - Updating a culture varying property throws SqlException (Cannot insert duplicate key row)

    I believe I found a bug on v8, updating a culture varying content through the content service. I already placed this issue. Anyway, I'm posting here, in case someone might help with a workaround or something.

    I'm developing a method to create or update some content in my project. I got stuck in a situation where the creation runs fine but the updates always fail with the following SqlException:

    Cannot insert duplicate key row in object 'dbo.umbracoPropertyData' with unique index 'IX_umbracoPropertyData_VersionId'. The duplicate key value is (2437, 145, 2, <NULL>). The statement has been terminated.
    

    I narrowed it down to a simple update of a culture varying property, using the content service.

    I have a TestVariant culture variant document type, with a culture varying bio property. Here's my code:

    var docType = Services.ContentTypeService.Get(TestVariant.ModelTypeAlias);
    
    // create a new content
    IContent newContent = new Content("My Content", -1, docType, "en-US");
    newContent.SetCultureName("My Content", "pt-PT");
    newContent.SetValue("bio", "original", "en-US");
    newContent.SetValue("bio", "original", "pt-PT");
    Services.ContentService.SaveAndPublish(newContent);
    
    // update a culture varying property
    var contentToUpdate = CS.GetById(newContent.Key);
    contentToUpdate.SetValue("bio", "updated", "en-US");
    contentToUpdate.SetValue("bio", "updated", "pt-PT");
    
    
    // Following line will throw exception: 
    // Message: Cannot insert duplicate key row in object 'dbo.umbracoPropertyData' with unique index 'IX_umbracoPropertyData_VersionId'. The duplicate key value is (2414, 51, 2, <NULL>)
    Services.ContentService.SaveAndPublish(contentToUpdate);
    
  • Filipe Neves 8 posts 28 karma points
    Apr 02, 2019 @ 15:19
    Filipe Neves
    0

    Got it: i should be using the culture ISO code pt and not pt-PT

  • Thomsen 113 posts 336 karma points
    Jun 07, 2019 @ 21:20
    Thomsen
    0

    Thanks, you saved my night ... :-)

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies