catch errors if model with pk is not found for scanning and generating

This commit is contained in:
wolflu05 2024-07-15 10:44:48 +02:00
parent 3999ae60db
commit 650787af55
No known key found for this signature in database
GPG Key ID: 9099EFC7C5EB963C
2 changed files with 10 additions and 3 deletions

View File

@ -162,7 +162,10 @@ class BarcodeGenerate(CreateAPIView):
if model_cls is None:
raise ValidationError({'error': _('Model is not supported')})
try:
model_instance = model_cls.objects.get(pk=pk)
except model_cls.DoesNotExist:
raise ValidationError({'error': _('Model instance not found')})
barcode_data = plugin.base.barcodes.helper.generate_barcode(model_instance)

View File

@ -76,8 +76,12 @@ class InvenTreeInternalBarcodePlugin(SettingsMixin, BarcodeMixin, InvenTreePlugi
return None
label = model.barcode_model_type()
pk = int(pk)
return self.format_matched_response(label, model, model.objects.get(pk=pk))
try:
instance = model.objects.get(pk=int(pk))
return self.format_matched_response(label, model, instance)
except (ValueError, model.DoesNotExist):
pass
# Internal Barcodes - JSON Format
# Attempt to coerce the barcode data into a dict object