Unicorn icon indicating copy to clipboard operation
Unicorn copied to clipboard

DuplicateItemName exception

Open bartlomiejmucha opened this issue 2 years ago • 2 comments

Do you want to request a feature or report a bug? Bug

What is the current behavior? Sitecore 10 does not allow having two items with the same name under one parent by default. If we have situation that we have two items with the same name under two different paths, for example:

/sitecore/templates/Foundation/Account/User /sitecore/templates/Features/Account/User

both under different unicorn configurations.

And if we at some point decide to move second item next to the first item but under different name, so we will have:

/sitecore/templates/Foundation/Account/User /sitecore/templates/Foundation/Account/User2

we will get DuplicateItemNameException.

I'm guessing that it's probably because unicorn tries to move the item first and then update it's name and this will not work as there is already an item with such name in the second path.

To fix that error we can manually update name of the first item to something else, and then unicorn sync works.

If the current behavior is a bug, please provide the steps to reproduce.

What is the expected behavior?

Not sure if this is possible, but would be good if unicorn could update the path and name of the item in the same time.

Please mention your Sitecore version and Unicorn version.

Sitecore 10.2 initial release; Unicorn 4.1.6

bartlomiejmucha avatar Mar 28 '22 14:03 bartlomiejmucha

Hmm not entirely sure I follow the scenario.

Not sure if this is possible, but would be good if unicorn could update the path and name of the item in the same time.

Path and name are interlocked; where "name" is just the tail end of the "path".

I'm guessing that it's probably because unicorn tries to move the item first and then update it's name and this will not work as there is already an item with such name in the second path.

Unicorn doesn't "move the item" at all. Sitecore does. Unicorn just reflects what's in Sitecore. Do you have the full stack trace of that DuplicateItemName exception?

To fix that error we can manually update name of the first item to something else, and then unicorn sync works.

Unicorn Sync is the process of taking what's on disk (yaml files) and updating the Sitecore content tree to reflect. When moving an item from one Unicorn configuration scope to another Unicorn configuration scope, you would need to perform a full reserialize of both configurations involved.

I would need some additional information to do anything with this. But generally speaking, if you move a Sitecore item with name "ItemA" to another part of the Sitecore content tree that already has an item named "ItemA" - you would run into an exception on certain Sitecore versions. And Unicorn plays no part in this.

cassidydotdk avatar Mar 28 '22 15:03 cassidydotdk

Here is the error from the logs. It's from my local tests. As you can see it can't move _Donation2 item because 'The item name "_Donation" is already defined on this level.'

We have the items master:/sitecore/templates/Feature/Form/_Donation master:/sitecore/templates/Foundation/Form/_Donation

and my colleague renamed the first one to Donation Base and moved to Foundation and he serialized changes to the repo. So in repo and in his database we have two items:

master:/sitecore/templates/Foundation/Form/_Donation Base (previously: master:/sitecore/templates/Feature/Form/_Donation) master:/sitecore/templates/Foundation/Form/_Donation

I pulled that change and I got such an error. I feel that I got that error because in my database I still have the first item under old name: (master:/sitecore/templates/Feature/Form/_Donation). To fix that issue I renamed that item to something else, and then sync went fine.

Not sure if this is a unicorn or Sitecore error. Or is it error at all, maybe it's a feature ;)

44940 15:31:35 ERROR ERROR: Some directories could not be loaded. (1 inner failures)
master:/sitecore/templates/Foundation/Form/_Donation2 (c247134c-aa4c-4e52-8af8-785310e8d1f5) (Unicorn.DeserializationAggregateException)
at Unicorn.Loader.DeserializeFailureRetryer.RetryAll(ISourceDataStore sourceDataStore, Action`1 retrySingleItemAction, Action`1 retryTreeAction)
at Unicorn.Loader.SerializationLoader.LoadAll(IItemData[] rootItemsData, IDeserializeFailureRetryer retryer, IConsistencyChecker consistencyChecker, Action`1 rootLoadedCallback)
at Unicorn.SerializationHelper.SyncTree(IConfiguration configuration, Action`1 rootLoadedCallback, Boolean runSyncStartPipeline, IItemData partialSyncRoot)
at Unicorn.SerializationHelper.SyncConfigurations(IConfiguration[] configurations, IProgressStatus progress, ILogger additionalLogger)

INNER EXCEPTION
master:/sitecore/templates/Foundation/Form/_Donation2 (c247134c-aa4c-4e52-8af8-785310e8d1f5) (Rainbow.Storage.Sc.Deserialization.DeserializationException)
No stack trace available.
INNER EXCEPTION
The item name "_Donation" is already defined on this level. (Sitecore.Exceptions.DuplicateItemNameException)
at Sitecore.Data.Items.ItemUtil.AssertDuplicateItemName(Item destinationItem, Item sourceItem, String name)
at Sitecore.Data.Items.Item.MoveTo(Item destination)
at Rainbow.Storage.Sc.Deserialization.DefaultDeserializer.GetOrCreateTargetItem(IItemData serializedItemData, Boolean& newItemWasCreated)
at Rainbow.Storage.Sc.Deserialization.DefaultDeserializer.Deserialize(IItemData serializedItemData, IFieldValueManipulator fieldValueManipulator)
at Rainbow.Storage.Sc.SitecoreDataStore.Save(IItemData item, IFieldValueManipulator fieldValueManipulator)
at Unicorn.Evaluators.SerializedAsMasterEvaluator.EvaluateUpdate(IItemData sourceItem, IItemData targetItem)
at Unicorn.Loader.SerializationLoader.DoLoadItem(IItemData serializedItemData, IConsistencyChecker consistencyChecker)
at Unicorn.Loader.DeserializeFailureRetryer.RetryAll(ISourceDataStore sourceDataStore, Action`1 retrySingleItemAction, Action`1 retryTreeAction)

bartlomiejmucha avatar Mar 29 '22 08:03 bartlomiejmucha