From bd35030c5928b9fce6b9c7fee1346abe69b999bc Mon Sep 17 00:00:00 2001 From: Trenton H <797416+stumpylog@users.noreply.github.com> Date: Fri, 5 Jan 2024 21:08:24 -0800 Subject: [PATCH] Fix: Crash in barcode ASN reading when the file type isn't supported (#5261) * Fixes a random crash in the barcode ASN reading so it doesn't try to access a not created temp dir * Don't parse the barcodes twice, store the result instead --- src/documents/barcodes.py | 5 ++++- src/documents/tasks.py | 7 +++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/documents/barcodes.py b/src/documents/barcodes.py index 005531107..5a2c3381a 100644 --- a/src/documents/barcodes.py +++ b/src/documents/barcodes.py @@ -90,6 +90,9 @@ class BarcodeReader: """ asn = None + if not self.supported_mime_type: + return None + # Ensure the barcodes have been read self.detect() @@ -215,7 +218,7 @@ class BarcodeReader: # This file is really borked, allow the consumption to continue # but it may fail further on except Exception as e: # pragma: no cover - logger.warning( + logger.exception( f"Exception during barcode scanning: {e}", ) diff --git a/src/documents/tasks.py b/src/documents/tasks.py index 19e40db5b..abb9cd39d 100644 --- a/src/documents/tasks.py +++ b/src/documents/tasks.py @@ -152,10 +152,13 @@ def consume_file( return "File successfully split" # try reading the ASN from barcode - if settings.CONSUMER_ENABLE_ASN_BARCODE and reader.asn is not None: + if ( + settings.CONSUMER_ENABLE_ASN_BARCODE + and (located_asn := reader.asn) is not None + ): # Note this will take precedence over an API provided ASN # But it's from a physical barcode, so that's good - overrides.asn = reader.asn + overrides.asn = located_asn logger.info(f"Found ASN in barcode: {overrides.asn}") template_overrides = Consumer().get_workflow_overrides(