Umbraco-CMS: Saving a Content Node with a Form chosen in a Block List results in a duplicate key exception for IX_umbracoRelation_parentChildType

Which Umbraco version are you using? (Please write the exact version, example: 10.1.0)

12.3.5, and Umbraco Forms 12.2.0

Bug summary

We have a Block List block that allows us to pick an Umbraco Form. When we save the content node for the first time it creates a Relationship between the Content Node and the Form.

If we subsequently attempt to save the page, it tries to add the relationship a second time, resulting in a duplicate key row.

Specifics

Cannot insert duplicate key row in object ‘dbo.umbracoRelation’ with unique index ‘IX_umbracoRelation_parentChildType’. The duplicate key value is (1497, 1624, 6). The statement has been terminated.

Exception Details

Microsoft.Data.SqlClient.SqlException, Microsoft.Data.SqlClient, Version=5.0.0.0, Culture=neutral, PublicKeyToken=23ec7fc2d6eaa4a5: Cannot insert duplicate key row in object 'dbo.umbracoRelation' with unique index 'IX_umbracoRelation_parentChildType'. The duplicate key value is (1497, 1624, 6). The statement has been terminated.

Stacktrace
at Microsoft.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   at Microsoft.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   at Microsoft.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
   at Microsoft.Data.SqlClient.SqlBulkCopy.RunParser(BulkCopySimpleResultSet bulkCopyHandler)
   at Microsoft.Data.SqlClient.SqlBulkCopy.CopyBatchesAsyncContinuedOnSuccess(BulkCopySimpleResultSet internalResults, String updateBulkCommandText, CancellationToken cts, TaskCompletionSource`1 source)
   at Microsoft.Data.SqlClient.SqlBulkCopy.CopyBatchesAsyncContinued(BulkCopySimpleResultSet internalResults, String updateBulkCommandText, CancellationToken cts, TaskCompletionSource`1 source)
   at Microsoft.Data.SqlClient.SqlBulkCopy.CopyBatchesAsync(BulkCopySimpleResultSet internalResults, String updateBulkCommandText, CancellationToken cts, TaskCompletionSource`1 source)
   at Microsoft.Data.SqlClient.SqlBulkCopy.WriteToServerInternalRestContinuedAsync(BulkCopySimpleResultSet internalResults, CancellationToken cts, TaskCompletionSource`1 source)
   at Microsoft.Data.SqlClient.SqlBulkCopy.WriteToServerInternalRestAsync(CancellationToken cts, TaskCompletionSource`1 source)
   at Microsoft.Data.SqlClient.SqlBulkCopy.WriteToServerInternalAsync(CancellationToken ctoken)
   at Microsoft.Data.SqlClient.SqlBulkCopy.WriteRowSourceToServerAsync(Int32 columnCount, CancellationToken ctoken)
   at Microsoft.Data.SqlClient.SqlBulkCopy.WriteToServer(DataTable table, DataRowState rowState)
   at Microsoft.Data.SqlClient.SqlBulkCopy.WriteToServer(DataTable table)
   at NPoco.SqlServer.SqlBulkCopyHelper.BulkInsert[T](IDatabase db, IEnumerable`1 list, SqlBulkCopyOptions sqlBulkCopyOptions, InsertBulkOptions insertBulkOptions)
   at NPoco.SqlServer.SqlBulkCopyHelper.BulkInsert[T](IDatabase db, IEnumerable`1 list, InsertBulkOptions insertBulkOptions)
   at NPoco.DatabaseTypes.SqlServerDatabaseType.InsertBulk[T](IDatabase db, IEnumerable`1 pocos, InsertBulkOptions options)
   at NPoco.Database.InsertBulk[T](IEnumerable`1 pocos, InsertBulkOptions options)
   at Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement.RelationRepository.SaveBulk(IEnumerable`1 relations)
   at Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement.ContentRepositoryBase`3.PersistRelations(TEntity entity)
   at Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement.DocumentRepository.PersistUpdatedItem(IContent entity)
   at Umbraco.Cms.Core.Cache.DefaultRepositoryCachePolicy`2.Update(TEntity entity, Action`1 persistUpdated)
   at Umbraco.Cms.Core.Services.ContentService.<>c__DisplayClass66_0.<CommitDocumentChangesInternal>g__SaveDocument|2(IContent c)
   at Umbraco.Cms.Core.Services.ContentService.CommitDocumentChangesInternal(ICoreScope scope, IContent content, EventMessages eventMessages, IReadOnlyCollection`1 allLangs, IDictionary`2 notificationState, Int32 userId, Boolean branchOne, Boolean branchRoot)
   at Umbraco.Cms.Core.Services.ContentService.SaveAndPublish(IContent content, String culture, Int32 userId)
   at Umbraco.Cms.Web.BackOffice.Controllers.ContentController.PublishInternal(ContentItemSave contentItem, String defaultCulture, String cultureForInvariantErrors, Boolean& wasCancelled, String[]& successfulCultures)
   at Umbraco.Cms.Web.BackOffice.Controllers.ContentController.PostSaveInternal[TVariant](ContentItemSave contentItem, Func`3 saveMethod, Func`2 mapToDisplay)
   at Umbraco.Cms.Web.BackOffice.Controllers.ContentController.PostSave(ContentItemSave contentItem)
   at lambda_method4033(Closure, Object)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(ActionContext actionContext, IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextExceptionFilterAsync>g__Awaited|26_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)

Steps to reproduce

  1. Add a Block List Element that has an Umbraco Form picker in it
  2. Add a Document Type with a Block List containing the configured Block List Element
  3. Add a new content node based on the Document Type, choose a form in the block list and save
  4. Attempt to save a second time - the exception should be thrown.

Expected result / actual result

Re-saving a content node with a form referenced in a block list element should not attempt to re-create the relationship between the form and the content node.

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Comments: 20 (10 by maintainers)

Most upvoted comments

I updated to 12.3.7 but I still get the same error. Earlier I could save the content after I added the the form but not a second time. Now I get the error the first time I save after adding the form.

Thanks Andy

I have not tried to upgrade to 13 yet. What I am worried about is that we use a LOT of old doc type grid editor stuff that we have just started to migrate to Block Grid. I would like to finish this migration before moving forward to v13.

Disabling relation tacking should be ok for us for now since we don’t have that many forms so it is quite easy to know where they are being used.

Yes, I’m expecting so. The related PRs have been merged into the 12 branch, and are labelled for a release in 12.4.

https://github.com/umbraco/Umbraco-CMS/pull/15593 https://github.com/umbraco/Umbraco-CMS/pull/15625

Hey y’all, this was an issue in the core and should be resolved in Umbraco v12.3.7. It should hopefully be released before the 9th.

Hey @robertjf, have a look at https://github.com/umbraco/Umbraco.Forms.Issues/issues/1129 and the related PR (https://github.com/umbraco/Umbraco-CMS/pull/15447) which explain this issue and provide a temporary (if a little hacky) workaround.