From 4d04588125ed9e027b419be1f28a0ee644ed38f4 Mon Sep 17 00:00:00 2001 From: Akim Juillerat Date: Fri, 31 Jan 2020 12:42:30 +0100 Subject: [PATCH] fixup! fixup! attachment_s3: Add set ACL function --- attachment_s3/models/ir_attachment.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/attachment_s3/models/ir_attachment.py b/attachment_s3/models/ir_attachment.py index e0b6814..f8135ba 100644 --- a/attachment_s3/models/ir_attachment.py +++ b/attachment_s3/models/ir_attachment.py @@ -16,7 +16,6 @@ _logger = logging.getLogger(__name__) try: import boto3 from botocore.exceptions import ClientError, EndpointConnectionError - from botocore.errorfactory import NoSuchKey except ImportError: boto3 = None # noqa ClientError = None # noqa @@ -128,14 +127,16 @@ class IrAttachment(models.Model): "ACL %s successfully set on object %s" % (acl, fname) ) return True - except NoSuchKey: - _logger.exception( - "Object %s does not exists on S3 bucket" % fname - ) - except ClientError: - _logger.exception( - "Cannot set ACL %s on object %s" % (acl, fname) - ) + except ClientError as e: + error_code = e.response['Error']['Code'] + if error_code == "NoSuchKey": + _logger.exception( + "Object %s does not exists on S3 bucket" % fname + ) + else: + _logger.exception( + "Cannot set ACL %s on object %s" % (acl, fname) + ) else: _logger.warning("Cannot set ACL on object not stored on S3") return False