From f9de3913ea557bbf4560232c4dfacdfac3004d0d Mon Sep 17 00:00:00 2001 From: Rui Lima <3x0dv5@users.noreply.github.com> Date: Sun, 8 Jul 2018 18:26:31 +0100 Subject: [PATCH] return 404 in DestroyModelMixin In case self.get_object() returns None we should return a 404. --- rest_framework/mixins.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rest_framework/mixins.py b/rest_framework/mixins.py index de10d6930..993571b2b 100644 --- a/rest_framework/mixins.py +++ b/rest_framework/mixins.py @@ -90,6 +90,8 @@ class DestroyModelMixin(object): """ def destroy(self, request, *args, **kwargs): instance = self.get_object() + if not instance: + return Response(status=status.HTTP_404_NOT_FOUND) self.perform_destroy(instance) return Response(status=status.HTTP_204_NO_CONTENT)