From 974c2737af5a1391b07b88a152513f7ab75194d0 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 30 Sep 2024 10:19:36 +1000 Subject: [PATCH] Add exception handling for default template creatoin (#8209) (#8211) (cherry picked from commit a71754b08623e17056a8415751aeb76da7deaf1e) Co-authored-by: Oliver --- src/backend/InvenTree/report/apps.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/backend/InvenTree/report/apps.py b/src/backend/InvenTree/report/apps.py index c5c874f79e..83e2979614 100644 --- a/src/backend/InvenTree/report/apps.py +++ b/src/backend/InvenTree/report/apps.py @@ -125,12 +125,14 @@ class ReportConfig(AppConfig): # Read the existing template file data = template_file.open('r').read() - logger.info("Creating new label template: '%s'", template['name']) - - # Create a new entry - report.models.LabelTemplate.objects.create( - **template, template=ContentFile(data, os.path.basename(filename)) - ) + try: + # Create a new entry + report.models.LabelTemplate.objects.create( + **template, template=ContentFile(data, os.path.basename(filename)) + ) + logger.info("Creating new label template: '%s'", template['name']) + except Exception: + pass def create_default_reports(self): """Create default report templates.""" @@ -212,9 +214,11 @@ class ReportConfig(AppConfig): # Read the existing template file data = template_file.open('r').read() - logger.info("Creating new report template: '%s'", template['name']) - # Create a new entry - report.models.ReportTemplate.objects.create( - **template, template=ContentFile(data, os.path.basename(filename)) - ) + try: + report.models.ReportTemplate.objects.create( + **template, template=ContentFile(data, os.path.basename(filename)) + ) + logger.info("Created new report template: '%s'", template['name']) + except Exception: + pass