From 5f19f534fce860be79e88a382ccfe4b7d2412759 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Wed, 17 Mar 2021 09:47:57 +1100 Subject: [PATCH] Catch error if invalid image is uploaded --- InvenTree/part/apps.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/InvenTree/part/apps.py b/InvenTree/part/apps.py index b1089cd57c..d08e7680fe 100644 --- a/InvenTree/part/apps.py +++ b/InvenTree/part/apps.py @@ -7,6 +7,7 @@ from django.db.utils import OperationalError, ProgrammingError from django.apps import AppConfig from django.conf import settings +from PIL import UnidentifiedImageError logger = logging.getLogger(__name__) @@ -44,9 +45,11 @@ class PartConfig(AppConfig): try: part.image.render_variations(replace=False) except FileNotFoundError: - logger.warning("Image file missing") + logger.warning(f"Image file '{part.image}' missing") part.image = None part.save() + except UnidentifiedImageError: + logger.warning(f"Image file '{part.image}' is invalid") except (OperationalError, ProgrammingError): # Exception if the database has not been migrated yet pass