From 03fab52da289c49335c4988bd26a6f6b49783565 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Tue, 31 May 2016 17:57:08 +0200 Subject: [PATCH] Prevent KeyError when thumbnail has no link. This can happen when the link isn't refreshing properly. It's better to show an empty thumbnail than a 500 Internal Server Error. --- pillarsdk/files.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pillarsdk/files.py b/pillarsdk/files.py index 75d12b9..b3250d5 100755 --- a/pillarsdk/files.py +++ b/pillarsdk/files.py @@ -71,7 +71,10 @@ class File(List, Find, Create, Post, Update, Delete, Replace): thumbnail = next((item for item in self['variations'] if item['size'] == size), None) if thumbnail: - return thumbnail['link'] + try: + return thumbnail['link'] + except KeyError: + return None if self.link: root, ext = os.path.splitext(self.link)