mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-28 11:36:44 +00:00
Exception handling for BulkDeleteMixin (#8205)
* Exception handling for BulkDeleteMixin * Fix unit test
This commit is contained in:
parent
390fec3ab1
commit
33499d61bd
@ -379,11 +379,26 @@ class BulkDeleteMixin:
|
|||||||
|
|
||||||
# Filter by provided item ID values
|
# Filter by provided item ID values
|
||||||
if items:
|
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
|
# Filter by provided filters
|
||||||
if 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)
|
# Run a final validation step (should raise an error if the deletion should not proceed)
|
||||||
self.validate_delete(queryset, request)
|
self.validate_delete(queryset, request)
|
||||||
|
@ -1874,7 +1874,7 @@ class StockTestResultTest(StockAPITestCase):
|
|||||||
# Now, let's delete all the newly created items with a single API request
|
# Now, let's delete all the newly created items with a single API request
|
||||||
# However, we will provide incorrect filters
|
# However, we will provide incorrect filters
|
||||||
response = self.delete(
|
response = self.delete(
|
||||||
url, {'items': tests, 'filters': {'stock_item': 10}}, expected_code=204
|
url, {'items': tests, 'filters': {'stock_item': 10}}, expected_code=400
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertEqual(StockItemTestResult.objects.count(), n + 50)
|
self.assertEqual(StockItemTestResult.objects.count(), n + 50)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user