[PATCH] REST: squish final open-codings of get_object_or_404

Daniel Axtens dja at axtens.net
Mon Aug 23 18:49:38 AEST 2021


Applied in order to apply Raxel's first 2 patches.

Daniel Axtens <dja at axtens.net> writes:

> 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 <dja at axtens.net>
> ---
>  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 0c578b44f1cb..e9c52b990080 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.30.2


More information about the Patchwork mailing list