diff --git a/src/backend/InvenTree/plugin/base/barcodes/api.py b/src/backend/InvenTree/plugin/base/barcodes/api.py index 095f6a8d4a..01b2f6ae9b 100644 --- a/src/backend/InvenTree/plugin/base/barcodes/api.py +++ b/src/backend/InvenTree/plugin/base/barcodes/api.py @@ -162,7 +162,10 @@ class BarcodeGenerate(CreateAPIView): if model_cls is None: raise ValidationError({'error': _('Model is not supported')}) - model_instance = model_cls.objects.get(pk=pk) + 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) diff --git a/src/backend/InvenTree/plugin/builtin/barcodes/inventree_barcode.py b/src/backend/InvenTree/plugin/builtin/barcodes/inventree_barcode.py index a16e29673e..d300e5ad3c 100644 --- a/src/backend/InvenTree/plugin/builtin/barcodes/inventree_barcode.py +++ b/src/backend/InvenTree/plugin/builtin/barcodes/inventree_barcode.py @@ -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