Skip to content

Commit

Permalink
Exception handling for BulkDeleteMixin
Browse files Browse the repository at this point in the history
  • Loading branch information
SchrodingersGat committed Sep 29, 2024
1 parent 390fec3 commit 558b810
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/backend/InvenTree/InvenTree/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,11 +379,26 @@ def delete(self, request, *args, **kwargs):

# Filter by provided item ID values
if items:
queryset = queryset.filter(id__in=items)
try:
queryset = queryset.filter(id__in=items)
except Exception:
raise ValidationError({
'non_field_errors': _('Invalid items list provided')
})

# Filter by provided filters
if filters:
queryset = queryset.filter(**filters)
try:
queryset = queryset.filter(**filters)
except Exception:
raise ValidationError({
'non_field_errors': _('Invalid filters provided')
})

if queryset.count() == 0:
raise ValidationError({
'non_field_errors': _('No items found to delete')
})

# Run a final validation step (should raise an error if the deletion should not proceed)
self.validate_delete(queryset, request)
Expand Down

0 comments on commit 558b810

Please sign in to comment.