Skip to content

Commit

Permalink
Order by tag name to ensure consistent ordering of tags in API results.
Browse files Browse the repository at this point in the history
  • Loading branch information
rtibbles committed Jun 15, 2021
1 parent 5234a96 commit 5b2de43
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
10 changes: 7 additions & 3 deletions kolibri/core/content/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]]
Expand Down
6 changes: 5 additions & 1 deletion kolibri/core/content/test/test_content_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 5b2de43

Please sign in to comment.