Delete created resource when it fails the relationship verification.

This commit is contained in:
Aaron Tan
2016-10-27 16:27:42 -04:00
parent ad04015c9f
commit 02cccf35d3
2 changed files with 6 additions and 2 deletions

View File

@@ -412,6 +412,8 @@ class SubListCreateAttachDetachAPIView(SubListCreateAPIView):
# Verify that the relationship to be added is valid.
attach_errors = self.is_valid_relation(parent, sub)
if attach_errors is not None:
if created:
sub.delete()
return Response(attach_errors, status=status.HTTP_400_BAD_REQUEST)
# Attach the object to the collection.