Skip to content

Commit

Permalink
Fixing collection/verison hard delete failure | should delete referen…
Browse files Browse the repository at this point in the history
…ces and expansions first
  • Loading branch information
snyaggarwal committed Oct 4, 2023
1 parent 3c16b60 commit dd9a243
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
15 changes: 8 additions & 7 deletions core/collections/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ def update(self, request, *args, **kwargs):
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)


class CollectionVersionRetrieveUpdateDestroyView(CollectionBaseView, RetrieveAPIView, UpdateAPIView):
class CollectionVersionRetrieveUpdateDestroyView(CollectionBaseView, RetrieveAPIView, UpdateAPIView, TaskMixin):
serializer_class = CollectionVersionDetailSerializer

def get_permissions(self):
Expand Down Expand Up @@ -690,14 +690,15 @@ def update(self, request, *args, **kwargs):
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

def delete(self, _, **kwargs): # pylint: disable=unused-argument
instance = self.get_object()
result = self.perform_task(delete_collection, (self.get_object().id,))

try:
instance.delete()
except ValidationError as ex:
return Response(ex.message_dict, status=status.HTTP_400_BAD_REQUEST)
if isinstance(result, Response):
return result

return Response(status=status.HTTP_204_NO_CONTENT)
if result is True:
return Response({'detail': DELETE_SUCCESS}, status=status.HTTP_204_NO_CONTENT)

return Response({'detail': get(result, 'messages', [DELETE_FAILURE])}, status=status.HTTP_400_BAD_REQUEST)


class CollectionVersionExpansionsView(CollectionBaseView, ListWithHeadersMixin, CreateAPIView):
Expand Down
2 changes: 2 additions & 0 deletions core/common/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ def delete_collection(collection_id):

try:
logger.info('Found collection %s. Beginning purge...', collection.mnemonic)
collection.references.all().delete()
collection.expansions.all().delete()
collection.delete(force=True)
logger.info('Delete complete!')
return True
Expand Down

0 comments on commit dd9a243

Please sign in to comment.