From 3c64733e93f56a184890469452fa69e7e8505d54 Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Mon, 16 Aug 2021 10:33:57 +0200 Subject: [PATCH] Fix crash trying to thumbnail invalid image --- src/pretix/base/models/event.py | 15 +++++++++++++-- src/pretix/helpers/templatetags/thumb.py | 2 +- src/pretix/presale/views/widget.py | 7 ++++++- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/pretix/base/models/event.py b/src/pretix/base/models/event.py index cd2b9c51c9..f84e3e8460 100644 --- a/src/pretix/base/models/event.py +++ b/src/pretix/base/models/event.py @@ -20,6 +20,7 @@ # . # +import logging # This file is based on an earlier version of pretix which was released under the Apache License 2.0. The full text of # the Apache License 2.0 can be obtained at . # @@ -73,6 +74,8 @@ from pretix.helpers.thumb import get_thumbnail from ..settings import settings_hierarkey from .organizer import Organizer, Team +logger = logging.getLogger(__name__) + class EventMixin: def clean(self): @@ -534,9 +537,17 @@ class Event(EventMixin, LoggedModel): logo_file = self.settings.get('logo_image', as_type=str, default='')[7:] og_file = self.settings.get('og_image', as_type=str, default='')[7:] if og_file: - img = get_thumbnail(og_file, '1200').thumb.url + try: + img = get_thumbnail(og_file, '1200').thumb.url + except: + logger.exception(f'Failed to create thumbnail of {og_file}') + img = default_storage.url(og_file) elif logo_file: - img = get_thumbnail(logo_file, '5000x120').thumb.url + try: + img = get_thumbnail(logo_file, '5000x1200').thumb.url + except: + logger.exception(f'Failed to create thumbnail of {logo_file}') + img = default_storage.url(logo_file) if img: return urljoin(build_absolute_uri(self, 'presale:event.index'), img) diff --git a/src/pretix/helpers/templatetags/thumb.py b/src/pretix/helpers/templatetags/thumb.py index 7d75c54b1e..9018ecf7ad 100644 --- a/src/pretix/helpers/templatetags/thumb.py +++ b/src/pretix/helpers/templatetags/thumb.py @@ -38,5 +38,5 @@ def thumb(source, arg): try: return get_thumbnail(source, arg).thumb.url except: - logger.exception('Failed to create thumbnail') + logger.exception(f'Failed to create thumbnail of {source}') return default_storage.url(source) diff --git a/src/pretix/presale/views/widget.py b/src/pretix/presale/views/widget.py index 41bacfc073..c310525238 100644 --- a/src/pretix/presale/views/widget.py +++ b/src/pretix/presale/views/widget.py @@ -208,7 +208,12 @@ def price_dict(item, price): def get_picture(event, picture): - return urljoin(build_absolute_uri(event, 'presale:event.index'), get_thumbnail(picture.name, '60x60^').thumb.url) + try: + thumb = get_thumbnail(picture.name, '60x60^').thumb.url + except: + logger.exception(f'Failed to create thumbnail of {picture.name}') + thumb = default_storage.url(picture.name) + return urljoin(build_absolute_uri(event, 'presale:event.index'), thumb) class WidgetAPIProductList(EventListMixin, View):