Catch error if invalid image is uploaded

This commit is contained in:
Oliver Walters 2021-03-17 09:47:57 +11:00
parent 15678f789c
commit 5f19f534fc

View File

@ -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