umbraco / Umbraco-CMS

Umbraco is a free and open source .NET content management system helping you deliver delightful digital experiences.
https://umbraco.com
MIT License
4.42k stars 2.67k forks source link

v9: SQL error when trying to create a new property on a tab or group (SQL CE) #11677

Closed hifi-phil closed 1 year ago

hifi-phil commented 2 years ago

Which exact Umbraco version are you using? For example: 9.0.1 - don't just write v9

9.1

Bug summary

A SQL error is generated when trying to create a new property on a tab or group. The error is: A duplicate value cannot be inserted into a unique index. [ Table name = cmsPropertyTypeGroup,Constraint name = IX_cmsPropertyTypeGroupUniqueID ].

This db has been migrated from 8.13 to 9.1. I have seen that there is a separate issue for this that has been fixed 11221 I tried upgrading from 9.01 to 9.1 and it still didn't fix the issue.

Specifics

A duplicate value cannot be inserted into a unique index. [ Table name = cmsPropertyTypeGroup,Constraint name = PK_cmsPropertyTypeGroup ]

Exception Details
System.Data.SqlServerCe.SqlCeException, System.Data.SqlServerCe, Version=4.0.0.1, Culture=neutral, PublicKeyToken=89845dcd8080cc91: A duplicate value cannot be inserted into a unique index. [ Table name = cmsPropertyTypeGroup,Constraint name = PK_cmsPropertyTypeGroup ]
Stacktrace
at System.Data.SqlServerCe.SqlCeCommand.ProcessResults(Int32 hr)
   at System.Data.SqlServerCe.SqlCeCommand.ExecuteCommandText(IntPtr& pCursor, Boolean& isBaseTableCursor)
   at System.Data.SqlServerCe.SqlCeCommand.ExecuteCommand(CommandBehavior behavior, String method, ResultSetOptions options)
   at System.Data.SqlServerCe.SqlCeCommand.ExecuteNonQuery()
   at Umbraco.Cms.Infrastructure.Persistence.FaultHandling.RetryPolicy.ExecuteAction[TResult](Func`1 func)
   at NPoco.Database.ExecuteNonQueryHelper(DbCommand cmd)
   at NPoco.DatabaseTypes.SqlServerCEDatabaseType.ExecuteInsert[T](Database db, DbCommand cmd, String primaryKeyName, Boolean useOutputClause, T poco, Object[] args)
   at NPoco.Database.InsertImp[T](PocoData pocoData, String tableName, String primaryKeyName, Boolean autoIncrement, T poco)
   at NPoco.Database.Insert[T](String tableName, String primaryKeyName, Boolean autoIncrement, T poco)
   at NPoco.Database.Insert[T](T poco)
   at Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement.ContentTypeRepositoryBase`1.PersistUpdatedBaseContentType(IContentTypeComposition entity)
   at Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement.ContentTypeRepository.PersistUpdatedItem(IContentType entity)
   at Umbraco.Cms.Core.Cache.FullDataSetRepositoryCachePolicy`2.Update(TEntity entity, Action`1 persistUpdated)
   at Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement.EntityRepositoryBase`2.Save(TEntity entity)
   at Umbraco.Cms.Core.Services.Implement.ContentTypeServiceBase`2.Save(TItem item, Int32 userId)
   at Umbraco.Cms.Web.BackOffice.Controllers.ContentTypeController.<PostSave>b__30_1(IContentType type)
   at Umbraco.Cms.Web.BackOffice.Controllers.ContentTypeControllerBase`1.PerformPostSave[TContentTypeDisplay,TContentTypeSave,TPropertyType](TContentTypeSave contentTypeSave, Func`2 getContentType, Action`1 saveContentType, Action`1 beforeCreateNew)
   at Umbraco.Cms.Web.BackOffice.Controllers.ContentTypeController.PostSave(DocumentTypeSave contentTypeSave)
   at lambda_method4530(Closure , Object , Object[] )
   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()
--- End of stack trace from previous location ---
   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|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)

Steps to reproduce

Add a tab or a new group Add a new property Click Save and Publish

Expected result / actual result

It saves the document type

tompipe commented 2 years ago

Hey Phil,

Had the same issue, maybe the following will help?

https://github.com/umbraco/Umbraco-CMS/issues/11522#issuecomment-1013904873

hifi-phil commented 2 years ago

Thanks Tom, I'll take a look

On Sun, Jan 16, 2022 at 4:19 PM Tom Pipe @.***> wrote:

Hey Phil,

Had the same issue, maybe the following will help?

11522 (comment)

https://github.com/umbraco/Umbraco-CMS/issues/11522#issuecomment-1013904873

— Reply to this email directly, view it on GitHub https://github.com/umbraco/Umbraco-CMS/issues/11677#issuecomment-1013905380, or unsubscribe https://github.com/notifications/unsubscribe-auth/AF6MVEDCFL7VHY5P5PORHP3UWLVYFANCNFSM5IQ26TCA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you authored the thread.Message ID: @.***>

--

Hi-Fi Ltd

web: www.hifi.agency email: @.*** telephone: 07966695017

Registered in England and Wales Company Number 9281128 VAT Number 221 9499 94

kjac commented 1 year ago

Hi @hifi-phil,

Thank you for reporting this; sorry for the quite late reply.

I can't reproduce this at all, neither on upgraded databases nor on newly created ones 😞 did you ever figure out what was going on, or did the suggested fix solve it for you?

hifi-phil commented 1 year ago

The fix from Tom solved the problem thanks...

On Thu, Jan 12, 2023 at 6:54 PM Kenn Jacobsen @.***> wrote:

Hi @hifi-phil https://github.com/hifi-phil,

Thank you for reporting this; sorry for the quite late reply.

I can't reproduce this at all, neither on upgraded databases nor on newly created ones 😞 did you ever figure out what was going on, or did the suggested fix solve it for you?

— Reply to this email directly, view it on GitHub https://github.com/umbraco/Umbraco-CMS/issues/11677#issuecomment-1380866767, or unsubscribe https://github.com/notifications/unsubscribe-auth/AF6MVEGL7LMSV7M7RRWBYF3WSBHOJANCNFSM5IQ26TCA . You are receiving this because you were mentioned.Message ID: @.***>

--

Hi-Fi Ltd

web: www.hifi.agency email: @.*** telephone: 07966695017

Registered in England and Wales Company Number 9281128 VAT Number 221 9499 94

kjac commented 1 year ago

Thanks for getting back to us @hifi-phil 💪

I'm going to close this issue since it's gone rather stale and we currently have no means of reproducing it.

If anyone encounters it again we would really love to hear about it, ideally with some steps to recreate the scenario 🙏