diff --git a/kolibri/core/content/api.py b/kolibri/core/content/api.py index 20af6070b08..526595dc35a 100644 --- a/kolibri/core/content/api.py +++ b/kolibri/core/content/api.py @@ -314,9 +314,13 @@ def get_related_data_maps(self, items, queryset): tags_map = {} - for t in models.ContentTag.objects.filter(tagged_content__in=queryset).values( - "tag_name", - "tagged_content", + for t in ( + models.ContentTag.objects.filter(tagged_content__in=queryset) + .values( + "tag_name", + "tagged_content", + ) + .order_by("tag_name") ): if t["tagged_content"] not in tags_map: tags_map[t["tagged_content"]] = [t["tag_name"]] diff --git a/kolibri/core/content/test/test_content_app.py b/kolibri/core/content/test/test_content_app.py index d79088b69a0..b452af17a98 100644 --- a/kolibri/core/content/test/test_content_app.py +++ b/kolibri/core/content/test/test_content_app.py @@ -310,7 +310,11 @@ def _assert_node(self, actual, expected): "rght": expected.rght, "tree_id": expected.tree_id, "ancestors": list(expected.get_ancestors().values("id", "title")), - "tags": list(expected.tags.all().values_list("tag_name", flat=True)), + "tags": list( + expected.tags.all() + .order_by("tag_name") + .values_list("tag_name", flat=True) + ), "assessmentmetadata": assessmentmetadata, "is_leaf": expected.kind != "topic", "files": files,