diff --git a/contentcuration/kolibri_public/tests/test_public_v1_api.py b/contentcuration/kolibri_public/tests/test_public_v1_api.py index 38464ce54b..6d545dbb11 100644 --- a/contentcuration/kolibri_public/tests/test_public_v1_api.py +++ b/contentcuration/kolibri_public/tests/test_public_v1_api.py @@ -477,3 +477,45 @@ def test_non_public_channel_token_returns_library_null(self): response = self.client.get(lookup_url) self.assertEqual(response.status_code, 200) self.assertIsNone(response.data[0]["library"]) + + def test_channel_version_with_none_version_returns_all_version_notes(self): + """ + When a ChannelVersion has version=None, _get_version_notes must not raise + TypeError and must return all entries from channel.published_data. + """ + self.channel.main_tree.published = True + self.channel.main_tree.save() + + self.channel.published_data = { + "1": {"version_notes": "v1 notes"}, + "3": {"version_notes": "v3 notes"}, + } + # Set channel.version so Channel.on_update() auto-creates ChannelVersion(version=3). + self.channel.version = 3 + self.channel.save() + + # Manually create a ChannelVersion with version=None to reproduce the Sentry bug. + channel_version, _created = ChannelVersion.objects.get_or_create( + channel=self.channel, + version=None, + defaults={ + "kind_count": [], + "included_languages": [], + "resource_count": 0, + "size": 0, + }, + ) + version_token = channel_version.new_token().token + + lookup_url = reverse( + "get_public_channel_lookup", + kwargs={"version": "v1", "identifier": version_token}, + ) + response = self.client.get(lookup_url + "?channel_versions=true") + + self.assertEqual(response.status_code, 200) + self.assertEqual(len(response.data), 1) + self.assertEqual( + response.data[0]["version_notes"], + {1: "v1 notes", 3: "v3 notes"}, + ) diff --git a/contentcuration/kolibri_public/views_v1.py b/contentcuration/kolibri_public/views_v1.py index c3ad838af0..2c0c4ef071 100644 --- a/contentcuration/kolibri_public/views_v1.py +++ b/contentcuration/kolibri_public/views_v1.py @@ -36,7 +36,7 @@ def _get_version_notes(channel, channel_version): data = { int(k): v["version_notes"] for k, v in channel.published_data.items() - if int(k) <= channel_version.version + if channel_version.version is None or int(k) <= channel_version.version } return OrderedDict(sorted(data.items()))