Retention Policy Failure - An item with the same key has already been added

Got an issue with applying retention policies which doesn’t have an obvious resolution that I can see so I’m after a little assistance…

Gets to the “Apply package metadata retention policy” step before failing with the following error:

An item with the same key has already been added.
System.ArgumentException
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary2.Insert(TKey key, TValue value, Boolean add) at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable1 source, Func2 keySelector, Func2 elementSelector, IEqualityComparer1 comparer) at Octopus.Core.PackageMetadata.PackageMetadataCleaner.<>c.<Execute>b__6_2(IGrouping2 packageReferenceGroup)
at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable1 source, Func2 keySelector, Func2 elementSelector, IEqualityComparer1 comparer)
at Octopus.Core.PackageMetadata.PackageMetadataCleaner.Execute(ICollection`1 packagesUsedByReleases, CancellationToken cancellationToken)
at Octopus.Server.Orchestration.ServerTasks.ApplyRetentionPolicies.ApplyRetentionPoliciesTaskController.ApplyPackageRetention()
at Octopus.Server.Orchestration.ServerTasks.ApplyRetentionPolicies.ApplyRetentionPoliciesTaskController.Execute()
at Octopus.Server.Orchestration.ServerTasks.RunningTask.RunMainThread()

Octopus v2019.4.2.

Any help appreciated :slight_smile:

Also seeing this issue after updating to 2019.4.2

I, too, am having this issue (same stack trace) and I just upgraded from 2018.12.0 to 2019.4.2. I checked to see if it was something obvious like a duplicate package ID and version on the NugetPackage table (didn’t find any), or something on the PackageMetadata table (it’s empty) so I’m at a loss for how to go about working around the issue.

One thing I’ll mention is that the Apply retention policies Task just stops after the error. Perhaps it could instead log the error for that step, but then also continue processing the remaining retention policies of the events and deployment manifests.

Hi all,

Thanks for reaching out and apologies that you’ve hit this issue. We have confirmed this is a bug and have a fix ready to ship in 2019.4.3. The issue came about through a check across the packages to determine whether retention needed to be applied, unfortunately we had missed the case where multiple steps referred to the same package/version combination.

Again, sorry for the inconvenience caused and we are looking to have this patch available in the next day or so.

Regards
Shannon

Thanks, Shannon. The quick turn-around is much appreciated, as always. Is there a GitHub issue that’s tracking the defect?

There is see https://github.com/OctopusDeploy/Issues/issues/5473.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.