Umbraco-CMS
Umbraco-CMS copied to clipboard
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
- Add a Block List Element that has an Umbraco Form picker in it
- Add a Document Type with a Block List containing the configured Block List Element
- Add a new content node based on the Document Type, choose a form in the block list and save
- 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.
Hi there @robertjf!
Firstly, a big thank you for raising this issue. Every piece of feedback we receive helps us to make Umbraco better.
We really appreciate your patience while we wait for our team to have a look at this but we wanted to let you know that we see this and share with you the plan for what comes next.
- We'll assess whether this issue relates to something that has already been fixed in a later version of the release that it has been raised for.
- If it's a bug, is it related to a release that we are actively supporting or is it related to a release that's in the end-of-life or security-only phase?
- We'll replicate the issue to ensure that the problem is as described.
- We'll decide whether the behavior is an issue or if the behavior is intended.
We wish we could work with everyone directly and assess your issue immediately but we're in the fortunate position of having lots of contributions to work with and only a few humans who are able to do it. We are making progress though and in the meantime, we will keep you in the loop and let you know when we have any questions.
Thanks, from your friendly Umbraco GitHub bot :robot: :slightly_smiling_face:
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.
I noticed this as well on an Umbraco Cloud project on Umbraco v12.2.0 and Forms v12.2.1
I have the same issue in Umbraco 12.3.5 and forms 12.2.1
I'm also experiencing it on multiple projects. Umbraco 12.3.5 and Forms 12.2.1
We are also experiencing it in Umbraco v12.3.6 and Umbraco Forms v12.2.2
We are also experiencing it in Umbraco v12.3.6 and Umbraco Forms v12.2.2
Same here. Just updated to the same for both Umbraco and Umbraco Forms. Experiencing the same issue.
Same issue here, Umbraco v12.3.6 and Umbraco Forms v12.2.2
Also experiencing this issue on Umbraco v12.3.6 and Umbraco Forms v12.2.2
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.
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.
We just did the same and is still experiencing it, both on exisiting items and newly created items.
We are also experiencing it in Umbraco v12.3.6 and Umbraco Forms v12.2.2
Same here. Just updated to the same for both Umbraco and Umbraco Forms. Experiencing the same issue.
In case some people haven't seen it. We've implemented @AndyButland's workaround suggestion for the moment and it's working for us: https://github.com/umbraco/Umbraco.Forms.Issues/issues/1129#issuecomment-1854426349
Basically just "add a form picker property directly on the document type in question". We made a composition with a form picker on it and added to the bottom of all doc types that use form pickers in block lists. Not ideal, but got the pages working again.
We upgraded to 13.1.1 and got rid of the issue. not a fix but a path
Will this be fixed for 12.x aswell?
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
Thanks for quick reply Andy :) Any estimations on when 12.4 will be released?
I've checked in with the CMS team, and It's not scheduled yet @Abrissirba - my expectation would be that if something critical comes up it would get pulled forward, but currently focus as you might expect is on preparation for Umbraco 14.
Correct me if I'm wrong, but as I understand this issue can be resolved by upgrading to 13 - which should be a fairly straightforward upgrade so worth doing if you can - or, if did feel you needed to stay on 12, there is a workaround or you could disable the form relations tracking feature if it won't work in your setup (where you have forms within blocks).
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.
I've checked in with the CMS team, and It's not scheduled yet @Abrissirba - my expectation would be that if something critical comes up it would get pulled forward, but currently focus as you might expect is on preparation for Umbraco 14.
Correct me if I'm wrong, but as I understand this issue can be resolved by upgrading to 13 - which should be a fairly straightforward upgrade so worth doing if you can - or, if did feel you needed to stay on 12, there is a workaround or you could disable the form relations tracking feature if it won't work in your setup (where you have forms within blocks).
Is an upgrade to forms v13 an option in v12 or do we need to implement the workaround?