Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix duplicate key exception in CompatibilitySorter #3908

Merged
merged 1 commit into from
Sep 18, 2023

Conversation

HebaruSan
Copy link
Member

@HebaruSan HebaruSan commented Sep 16, 2023

Problem

The metadata validator threw a duplicate key exception while checking KSP-CKAN/NetKAN#9800:

https://github.com/KSP-CKAN/NetKAN/actions/runs/6207962451/job/16853654203?pr=9800

  Unhandled Exception:
  System.ArgumentException: An item with the same key has already been added. Key: [kOS-EVA, CKAN.AvailableModule]
    at System.Collections.Generic.TreeSet`1[T].AddIfNotPresent (T item) [0x0001a] in <33b19a7ad5234d94abf4fd9b47566616>:0 
    at System.Collections.Generic.SortedSet`1[T].Add (T item) [0x00000] in <33b19a7ad5234d94abf4fd9b47566616>:0 
    at System.Collections.Generic.SortedDictionary`2[TKey,TValue].Add (TKey key, TValue value) [0x00020] in <33b19a7ad5234d94abf4fd9b47566616>:0 
    at CKAN.CompatibilitySorter.PartitionModules (System.Collections.Generic.IEnumerable`1[T] dicts, System.Collections.Generic.Dictionary`2[TKey,TValue] providers) [0x00114] in <f9f0ffbfa5e14bc18bf2f56116c5f6c1>:0 
    at CKAN.CompatibilitySorter..ctor (CKAN.Versioning.GameVersionCriteria crit, System.Collections.Generic.IEnumerable`1[T] available, System.Collections.Generic.Dictionary`2[TKey,TValue] providers, System.Collections.Generic.Dictionary`2[TKey,TValue] installed, System.Collections.Generic.HashSet`1[T] dlls, System.Collections.Generic.IDictionary`2[TKey,TValue] dlc) [0x0005b] in <f9f0ffbfa5e14bc18bf2f56116c5f6c1>:0 

Cause

The CompatibilitySorter from #2963 was updated to handle multiple source repos in #3904, but multiple AvailableModules with the same identifier weren't covered. This is essential for the metadata validator.

Changes

  • Now if the repositories contain multiple AvailableModules with the same identifier, the CompatibilitySorter merges them into one new AvailableModule containing the combined list of CkanModules; if there are multiple CkanModules with the same identifier and version, the module from the higher priority repo (defined as higher up in the list, so a lower number) takes precedence
  • A test is added to exercise this case, which fails without the fix and passes with it
  • AvailableModule.Remove wasn't being used and is deleted
    AvailableModule.Add is only being used internally so is now private

We may have to update the metadata validator after this to set the priority of the repositories to get the right modules to load; I think we were previously skating by on the coincidence that default comes before local alphabetically.

@HebaruSan HebaruSan added Bug Something is not working as intended Core (ckan.dll) Issues affecting the core part of CKAN Infrastructure Issues affecting everything around CKAN (the GitHub repos, build process, CI, ...) Tests Issues affecting the internal tests Registry Issues affecting the registry labels Sep 16, 2023
Copy link
Member

@techman83 techman83 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, and extra tests 😍 thanks @HebaruSan !

@HebaruSan HebaruSan merged commit 341adf8 into KSP-CKAN:master Sep 18, 2023
10 checks passed
@HebaruSan HebaruSan deleted the fix/comp-sort-merge-avail branch September 18, 2023 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something is not working as intended Core (ckan.dll) Issues affecting the core part of CKAN Infrastructure Issues affecting everything around CKAN (the GitHub repos, build process, CI, ...) Registry Issues affecting the registry Tests Issues affecting the internal tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants