An item with the same key has already been added when clicking Relations

Hi!
On a specific product we can no longer access the Relations tab without this exception:

System.ArgumentException: An item with the same key has already been added.
   at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
   at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
   at Litium.Web.Administration.WebApi.Products.Controllers.ProductsController.CreateRelationsModel(BaseProduct product, ICollection`1 variants)
   at Litium.Web.Administration.WebApi.Products.Controllers.ProductsController.GetInternal(Guid systemId, String tab, Boolean excludeProduct, List`1 includeVariants)
   at Litium.Web.Administration.WebApi.Products.Controllers.ProductsController.Get(Guid systemId, String tab)
   at lambda_method(Closure , Object , Object[] )
   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass6_2.<GetExecutor>b__2(Object instance, Object[] methodParameters)
   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at System.Web.Http.Tracing.ITraceWriterExtensions.<TraceBeginEndAsyncCore>d__17`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at System.Web.Http.Tracing.ITraceWriterExtensions.<TraceBeginEndAsyncCore>d__17`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Web.Http.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Web.Http.Filters.AuthorizationFilterAttribute.<ExecuteAuthorizationFilterAsyncCore>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Web.Http.Filters.AuthorizationFilterAttribute.<ExecuteAuthorizationFilterAsyncCore>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Web.Http.Filters.AuthorizationFilterAttribute.<ExecuteAuthorizationFilterAsyncCore>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at System.Web.Http.Controllers.ExceptionFilterResult.<ExecuteAsync>d__6.MoveNext()

Any idea why?

/Kristoffer

Litium version: 6.3.9

Can you access the database and inspect the data for that particular product? Sounds like there might be multiple links to the same related product.

Yes, I can but I cannot find anything. Maybe I’m looking in the wrong tables? Where should I look?
I guess you should not be able to add multiple links, the GUI should handle this right?

I’d check the Products.RelationshipLink table with FromBaseProductSystemId / FromVariantSystemId FromSystemId as the product you know is broken.

Yes, you shouldn’t be able to add the same relation multiple times.

Ok, is this query correkt:

  where FromBaseProductSystemId = '371719a2-5527-4540-b694-258a9ef30bb6'
  or FromVariantSystemId in ('485A372C-A459-43D6-B852-1FFC7FF6C093',
'371719A2-5527-4540-B694-258A9EF30BB6',
'971F0336-F163-46E5-A289-28D202E082D9',
'BF8F4360-EE6A-430A-9953-40CED3ADDE8F',
'3BD2BF74-43C9-45CA-B999-4B2B3B6E1088',
'E0771372-3BF7-41D0-B27A-5B12DAEEA17F',
'44A9FBFF-3105-4E42-B748-74C8BDD4BB00',
'00558658-AD24-488B-823D-CF7E2848AC7A',
'96116068-D092-44E1-84D4-E6AAAD521069',
'7404C68D-1D50-4B9D-86B7-F114A4A99CB7',
'6FCD91C7-1757-4B7D-B633-FED4FBDDF1BD')

That acutally gives me no hits in the database? Could there be a cache error that needs a site restart?

Yes, that looks correct. You could simplify to just use FromSystemId. Worth checking is also ToSystemId, in case the faulty connection is on the other end.

A restart is always useful to test.

Yes, that helped:

or ToSystemId in ('485A372C-A459-43D6-B852-1FFC7FF6C093',
'371719A2-5527-4540-B694-258A9EF30BB6',
'971F0336-F163-46E5-A289-28D202E082D9',
'BF8F4360-EE6A-430A-9953-40CED3ADDE8F',
'3BD2BF74-43C9-45CA-B999-4B2B3B6E1088',
'E0771372-3BF7-41D0-B27A-5B12DAEEA17F',
'44A9FBFF-3105-4E42-B748-74C8BDD4BB00',
'00558658-AD24-488B-823D-CF7E2848AC7A',
'96116068-D092-44E1-84D4-E6AAAD521069',
'7404C68D-1D50-4B9D-86B7-F114A4A99CB7',
'6FCD91C7-1757-4B7D-B633-FED4FBDDF1BD'
)

Where should I look for the duplicate? I cannot find anything strange by looking at the code.

As Nils wrote try with a restart if you can’t find any duplicates.

Ok, what column combination should create the duplicate? I’m not sure where to look.

I had the chance to look at the table a bit more and it has a Primary Key for RelationshipType, FromSystemId and ToSystemId so duplicates seems unlikely. Did you try restarting the application?

Hi!

Still the same after a restart. I will send a message to support about the customer so maybe you can look in the database directly?
Thanks!

/Kristoffer