Skip to content

Commit d4184a4

Browse files
authored
Merge pull request learningequality#5833 from rtibblesbot/issue-5832-c94420
fix: guard against None version in _get_version_notes
2 parents bed1c82 + e159cd7 commit d4184a4

2 files changed

Lines changed: 43 additions & 1 deletion

File tree

contentcuration/kolibri_public/tests/test_public_v1_api.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,3 +477,45 @@ def test_non_public_channel_token_returns_library_null(self):
477477
response = self.client.get(lookup_url)
478478
self.assertEqual(response.status_code, 200)
479479
self.assertIsNone(response.data[0]["library"])
480+
481+
def test_channel_version_with_none_version_returns_all_version_notes(self):
482+
"""
483+
When a ChannelVersion has version=None, _get_version_notes must not raise
484+
TypeError and must return all entries from channel.published_data.
485+
"""
486+
self.channel.main_tree.published = True
487+
self.channel.main_tree.save()
488+
489+
self.channel.published_data = {
490+
"1": {"version_notes": "v1 notes"},
491+
"3": {"version_notes": "v3 notes"},
492+
}
493+
# Set channel.version so Channel.on_update() auto-creates ChannelVersion(version=3).
494+
self.channel.version = 3
495+
self.channel.save()
496+
497+
# Manually create a ChannelVersion with version=None to reproduce the Sentry bug.
498+
channel_version, _created = ChannelVersion.objects.get_or_create(
499+
channel=self.channel,
500+
version=None,
501+
defaults={
502+
"kind_count": [],
503+
"included_languages": [],
504+
"resource_count": 0,
505+
"size": 0,
506+
},
507+
)
508+
version_token = channel_version.new_token().token
509+
510+
lookup_url = reverse(
511+
"get_public_channel_lookup",
512+
kwargs={"version": "v1", "identifier": version_token},
513+
)
514+
response = self.client.get(lookup_url + "?channel_versions=true")
515+
516+
self.assertEqual(response.status_code, 200)
517+
self.assertEqual(len(response.data), 1)
518+
self.assertEqual(
519+
response.data[0]["version_notes"],
520+
{1: "v1 notes", 3: "v3 notes"},
521+
)

contentcuration/kolibri_public/views_v1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def _get_version_notes(channel, channel_version):
3636
data = {
3737
int(k): v["version_notes"]
3838
for k, v in channel.published_data.items()
39-
if int(k) <= channel_version.version
39+
if channel_version.version is None or int(k) <= channel_version.version
4040
}
4141
return OrderedDict(sorted(data.items()))
4242

0 commit comments

Comments
 (0)