Fix loading of legacy registry.json files #3937
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
If you install some mods with the current release of CKAN and then switch to the current dev build, it will show no mods installed.
Thanks to @JonnyOThan for reporting this on Discord.
Cause
In #3904, we retired
Registry.available_modules
andRegistry.download_counts
. However, since the old client will crash if these are absent or null, we created aJsonAlwaysEmptyObjectConverter
to ensure they're always saved as an empty JSON object ({}
). This converter's deserialization function worked by simply creating an empty copy of the required type (Dictionary<string, string>
in this case).However, a
JsonConverter
'sReadJson
implementation must callJToken.Load(reader)
to extract the current token from the input stream! We weren't doing that, and the parse was stopping right after that point, beforeRegistry.installed_modules
was deserialized. MaybeNewtonsoft.Json
considers that an error condition?This doesn't happen with a "new" registry because it doesn't call the converter when the JSON object is already empty (I think).
Changes
Now
JsonAlwaysEmptyObjectConverter.ReadJson
callsJToken.Load(reader)
and ignores its return value before it returns the empty dictionary, which allows the fullRegistry
object to finish deserializing.I'll probably self-review this because it's small and a regression.