From 5610cbe735f37876326356c7d4dc4920a35e4111 Mon Sep 17 00:00:00 2001 From: Ryan Petrello Date: Tue, 31 Jul 2018 15:54:20 -0400 Subject: [PATCH] prevent host deletion when the related inventory is pending deletion see: https://github.com/ansible/tower/issues/2690 --- awx/api/views.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/awx/api/views.py b/awx/api/views.py index fc92ed1ac3..e241a692c2 100644 --- a/awx/api/views.py +++ b/awx/api/views.py @@ -2251,6 +2251,12 @@ class HostDetail(RelatedJobsPreventDeleteMixin, ControlledByScmMixin, RetrieveUp model = Host serializer_class = HostSerializer + def delete(self, request, *args, **kwargs): + if self.get_object().inventory.pending_deletion: + return Response({"error": _("The inventory for this host is already being deleted.")}, + status=status.HTTP_400_BAD_REQUEST) + return super(HostDetail, self).delete(request, *args, **kwargs) + class HostAnsibleFactsDetail(RetrieveAPIView):