mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-28 11:36:44 +00:00
* Exception handling for BulkDeleteMixin * Fix unit test (cherry picked from commit 33499d61bd522fb1fe24fb296fa09b361436574c) Co-authored-by: Oliver <oliver.henry.walters@gmail.com>
This commit is contained in:
parent
b12bd3bb4b
commit
0a0da7b65b
@ -383,11 +383,26 @@ class BulkDeleteMixin:
|
||||
|
||||
# Filter by provided item ID values
|
||||
if 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:
|
||||
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)
|
||||
|
@ -1713,7 +1713,7 @@ class StockTestResultTest(StockAPITestCase):
|
||||
# Now, let's delete all the newly created items with a single API request
|
||||
# However, we will provide incorrect filters
|
||||
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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user