Don't redefine exception but split the code

This commit is contained in:
Sander Steffann
2019-12-06 16:32:18 +01:00
committed by GitHub
parent a6f2d5b414
commit 02a009b7a7

View File

@@ -755,13 +755,16 @@ class ImageAttachment(models.Model):
""" """
from django.conf import settings from django.conf import settings
if settings.MEDIA_STORAGE and settings.MEDIA_STORAGE['BACKEND'] == 'S3': if settings.MEDIA_STORAGE and settings.MEDIA_STORAGE['BACKEND'] == 'S3':
from botocore.exceptions import ClientError as AccessError # For S3 we need to handle a different exception
else: from botocore.exceptions import ClientError
AccessError = OSError try:
return self.image.size
except ClientError:
return None
try: try:
return self.image.size return self.image.size
except AccessError: except OSError:
return None return None