From 6e4cf7c09213f177e6760678280e97d22a8f90d6 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Wed, 13 Jan 2021 22:07:30 +1100 Subject: [PATCH] Catch db integrity errors --- InvenTree/label/apps.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/InvenTree/label/apps.py b/InvenTree/label/apps.py index 74db58fe92..f93d6b7acc 100644 --- a/InvenTree/label/apps.py +++ b/InvenTree/label/apps.py @@ -75,13 +75,13 @@ class LabelConfig(AppConfig): logger.info(f"Copying label template '{dst_file}'") shutil.copyfile(src_file, dst_file) - # Check if a label matching the template already exists - if StockItemLabel.objects.filter(label=filename).exists(): - continue - - logger.info(f"Creating entry for StockItemLabel '{label['name']}'") - try: + # Check if a label matching the template already exists + if StockItemLabel.objects.filter(label=filename).exists(): + continue + + logger.info(f"Creating entry for StockItemLabel '{label['name']}'") + StockItemLabel.objects.create( name=label['name'], description=label['description'], @@ -89,7 +89,7 @@ class LabelConfig(AppConfig): filters='', enabled=True ) - except IntegrityError: + except: pass def create_stock_location_labels(self): @@ -151,13 +151,13 @@ class LabelConfig(AppConfig): logger.info(f"Copying label template '{dst_file}'") shutil.copyfile(src_file, dst_file) - # Check if a label matching the template already exists - if StockLocationLabel.objects.filter(label=filename).exists(): - continue - - logger.info(f"Creating entry for StockLocationLabel '{label['name']}'") - try: + # Check if a label matching the template already exists + if StockLocationLabel.objects.filter(label=filename).exists(): + continue + + logger.info(f"Creating entry for StockLocationLabel '{label['name']}'") + StockLocationLabel.objects.create( name=label['name'], description=label['description'], @@ -165,5 +165,5 @@ class LabelConfig(AppConfig): filters='', enabled=True ) - except IntegrityError: + except: pass