mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-10-31 05:05:42 +00:00 
			
		
		
		
	* Exception handling for BulkDeleteMixin
* Fix unit test
(cherry picked from commit 33499d61bd)
Co-authored-by: Oliver <oliver.henry.walters@gmail.com>
			
			
This commit is contained in:
		
				
					committed by
					
						 GitHub
						GitHub
					
				
			
			
				
	
			
			
			
						parent
						
							b12bd3bb4b
						
					
				
				
					commit
					0a0da7b65b
				
			| @@ -383,11 +383,26 @@ class BulkDeleteMixin: | ||||
|  | ||||
|             # 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) | ||||
|   | ||||
| @@ -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) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user