From 0ed2feb26c840fdfc3f9738dae6d7453da3ce16b Mon Sep 17 00:00:00 2001 From: Daniel Axtens Date: Mon, 23 Aug 2021 17:29:53 +1000 Subject: [PATCH] REST: squish final open-codings of get_object_or_404 Basically, finish the job of commit fecf7c86c2c5 ("urls: Add missing path converters for REST APIs"). With this commit, there are no more uses of Http404 in patchwork/api Signed-off-by: Daniel Axtens --- patchwork/api/comment.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/patchwork/api/comment.py b/patchwork/api/comment.py index 0c578b44..e9c52b99 100644 --- a/patchwork/api/comment.py +++ b/patchwork/api/comment.py @@ -5,7 +5,7 @@ import email.parser -from django.http import Http404 +from rest_framework.generics import get_object_or_404 from rest_framework.generics import ListAPIView from rest_framework.serializers import SerializerMethodField @@ -86,8 +86,7 @@ class CoverCommentList(ListAPIView): lookup_url_kwarg = 'pk' def get_queryset(self): - if not Cover.objects.filter(pk=self.kwargs['pk']).exists(): - raise Http404 + get_object_or_404(Cover, pk=self.kwargs['pk']) return CoverComment.objects.filter( cover=self.kwargs['pk'] @@ -105,8 +104,7 @@ class PatchCommentList(ListAPIView): lookup_url_kwarg = 'patch_id' def get_queryset(self): - if not Patch.objects.filter(id=self.kwargs['patch_id']).exists(): - raise Http404 + get_object_or_404(Patch, id=self.kwargs['patch_id']) return PatchComment.objects.filter( patch=self.kwargs['patch_id'] -- 2.47.3