From 02a009b7a72acfffe72b0076dbce74cbcd366e34 Mon Sep 17 00:00:00 2001 From: Sander Steffann Date: Fri, 6 Dec 2019 16:32:18 +0100 Subject: [PATCH] Don't redefine exception but split the code --- netbox/extras/models.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/netbox/extras/models.py b/netbox/extras/models.py index d74e14790..4056b0b1a 100644 --- a/netbox/extras/models.py +++ b/netbox/extras/models.py @@ -755,13 +755,16 @@ class ImageAttachment(models.Model): """ from django.conf import settings if settings.MEDIA_STORAGE and settings.MEDIA_STORAGE['BACKEND'] == 'S3': - from botocore.exceptions import ClientError as AccessError - else: - AccessError = OSError + # For S3 we need to handle a different exception + from botocore.exceptions import ClientError + try: + return self.image.size + except ClientError: + return None try: return self.image.size - except AccessError: + except OSError: return None