From 558b8102fe79ccc2c26c2db5fc44de1a47656a73 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sun, 29 Sep 2024 01:36:23 +0000 Subject: [PATCH] Exception handling for BulkDeleteMixin --- src/backend/InvenTree/InvenTree/api.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/backend/InvenTree/InvenTree/api.py b/src/backend/InvenTree/InvenTree/api.py index 7213f78cbd8b..0ebbfad8a131 100644 --- a/src/backend/InvenTree/InvenTree/api.py +++ b/src/backend/InvenTree/InvenTree/api.py @@ -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)