diff --git a/backend/code_review_backend/issues/api_v2.py b/backend/code_review_backend/issues/api_v2.py index bd955bfe5..bd6b37ca3 100644 --- a/backend/code_review_backend/issues/api_v2.py +++ b/backend/code_review_backend/issues/api_v2.py @@ -10,11 +10,11 @@ from rest_framework.generics import ListAPIView from code_review_backend.issues.models import Diff, IssueLink -from code_review_backend.issues.serializers import IssueHashSerializer +from code_review_backend.issues.serializers_v2 import IssueLinkHashSerializer class IssueList(ListAPIView): - serializer_class = IssueHashSerializer + serializer_class = IssueLinkHashSerializer allowed_modes = ["unresolved", "known", "closed"] @cached_property @@ -39,7 +39,7 @@ def distinct_issues(self, qs): Convert a list of issue links to unique couples of (issue_id, issue_hash) """ attributes = ("issue_id", "issue__hash") - return qs.order_by(*attributes).values_list(*attributes).distinct() + return qs.order_by(*attributes).values(*attributes).distinct() def get_unresolved(self): """ diff --git a/backend/code_review_backend/issues/serializers_v2.py b/backend/code_review_backend/issues/serializers_v2.py new file mode 100644 index 000000000..6252d65e1 --- /dev/null +++ b/backend/code_review_backend/issues/serializers_v2.py @@ -0,0 +1,15 @@ +from rest_framework import serializers + +from code_review_backend.issues.models import IssueLink + + +class IssueLinkHashSerializer(serializers.ModelSerializer): + """Serialize an Issue hash from the IssueLink M2M""" + + id = serializers.UUIDField(source="issue_id") + hash = serializers.CharField(source="issue__hash", max_length=32) + + class Meta: + model = IssueLink + fields = ("id", "hash") + read_only_fields = ("id", "hash")