2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-01 11:10:54 +00:00

Add more checks to pre-commit (#3132)

* Add bandit to pre-commit checks

* fix catchall exceptions

* remove unused definitons

* remove unuseed ariables

* Add docstring

* fix B006, B008 errors

* fix B007 error

* ignore B009

* Add checks for formatting and naming
This commit is contained in:
Matthias Mair
2022-06-06 00:56:52 +02:00
committed by GitHub
parent bbbfd003e0
commit f38386b13c
56 changed files with 154 additions and 109 deletions

View File

@ -99,7 +99,7 @@ class StockItemContextMixin:
try:
context['item'] = StockItem.objects.get(pk=self.kwargs.get('pk', None))
except:
except Exception:
pass
return context
@ -830,7 +830,7 @@ class StockList(APIDownloadMixin, generics.ListCreateAPIView):
if part.tree_id is not None:
queryset = queryset.filter(part__tree_id=part.tree_id)
except:
except Exception:
pass
# Filter by 'allocated' parts?
@ -1144,7 +1144,7 @@ class StockItemTestResultList(generics.ListCreateAPIView):
"""Set context before returning serializer."""
try:
kwargs['user_detail'] = str2bool(self.request.query_params.get('user_detail', False))
except:
except Exception:
pass
kwargs['context'] = self.get_serializer_context()
@ -1186,12 +1186,12 @@ class StockTrackingList(generics.ListAPIView):
"""Set context before returning serializer."""
try:
kwargs['item_detail'] = str2bool(self.request.query_params.get('item_detail', False))
except:
except Exception:
pass
try:
kwargs['user_detail'] = str2bool(self.request.query_params.get('user_detail', False))
except:
except Exception:
pass
kwargs['context'] = self.get_serializer_context()
@ -1219,7 +1219,7 @@ class StockTrackingList(generics.ListAPIView):
part = Part.objects.get(pk=deltas['part'])
serializer = PartBriefSerializer(part)
deltas['part_detail'] = serializer.data
except:
except Exception:
pass
# Add location detail
@ -1228,7 +1228,7 @@ class StockTrackingList(generics.ListAPIView):
location = StockLocation.objects.get(pk=deltas['location'])
serializer = StockSerializers.LocationSerializer(location)
deltas['location_detail'] = serializer.data
except:
except Exception:
pass
# Add stockitem detail
@ -1237,7 +1237,7 @@ class StockTrackingList(generics.ListAPIView):
stockitem = StockItem.objects.get(pk=deltas['stockitem'])
serializer = StockSerializers.StockItemSerializer(stockitem)
deltas['stockitem_detail'] = serializer.data
except:
except Exception:
pass
# Add customer detail
@ -1246,7 +1246,7 @@ class StockTrackingList(generics.ListAPIView):
customer = Company.objects.get(pk=deltas['customer'])
serializer = CompanySerializer(customer)
deltas['customer_detail'] = serializer.data
except:
except Exception:
pass
# Add purchaseorder detail
@ -1255,7 +1255,7 @@ class StockTrackingList(generics.ListAPIView):
order = PurchaseOrder.objects.get(pk=deltas['purchaseorder'])
serializer = PurchaseOrderSerializer(order)
deltas['purchaseorder_detail'] = serializer.data
except:
except Exception:
pass
if request.is_ajax():

View File

@ -56,7 +56,7 @@ def update_history(apps, schema_editor):
try:
deltas['quantity']: float(q)
updated = True
except:
except Exception:
print(f"WARNING: Error converting quantity '{q}'")
@ -89,7 +89,7 @@ def update_history(apps, schema_editor):
# Ensure that 'quantity' is stored too in this case
deltas['quantity'] = float(q)
except:
except Exception:
print(f"WARNING: Error converting removed quantity '{removed}'")
else:
print(f"Could not decode '{title}'")
@ -168,7 +168,7 @@ def update_history(apps, schema_editor):
# Ensure that 'quantity' is stored too in this case
deltas['quantity'] = float(q)
except:
except Exception:
print(f"WARNING: Error converting added quantity '{added}'")
else:

View File

@ -25,7 +25,7 @@ def update_serials(apps, schema_editor):
if result and len(result.groups()) == 1:
try:
serial = int(result.groups()[0])
except:
except Exception:
serial = 0

View File

@ -1300,8 +1300,12 @@ class StockItem(MetadataMixin, MPTTModel):
item.save()
@transaction.atomic
def copyTestResultsFrom(self, other, filters={}):
def copyTestResultsFrom(self, other, filters=None):
"""Copy all test results from another StockItem."""
# Set default - see B006
if filters is None:
filters = {}
for result in other.test_results.all().filter(**filters):
# Create a copy of the test result by nulling-out the pk

View File

@ -90,7 +90,7 @@ class StockTest(InvenTreeTestCase):
build = Build.objects.create(reference='12345', part=part, title='A test build', quantity=1)
# Add some stock items which are "building"
for i in range(10):
for _ in range(10):
StockItem.objects.create(
part=part, build=build,
quantity=10, is_building=True
@ -439,7 +439,7 @@ class StockTest(InvenTreeTestCase):
serial=i,
quantity=1,
)
except:
except Exception:
pass
item_next = item.get_next_serialized_item()
@ -616,7 +616,7 @@ class StockTest(InvenTreeTestCase):
# - C32 should move directly under A
# Add some stock items to B3
for i in range(10):
for _ in range(10):
StockItem.objects.create(
part=Part.objects.get(pk=1),
quantity=10,