From b933886c0037e3eba3e805194063dd6eb92de5cd Mon Sep 17 00:00:00 2001 From: Artem Loginov Date: Fri, 21 Jul 2023 14:34:03 +0300 Subject: [PATCH] Return None on NoSuchKey error from s3 to cache the file. --- tc_aws/storages/s3_storage.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tc_aws/storages/s3_storage.py b/tc_aws/storages/s3_storage.py index f258c28..4232b91 100644 --- a/tc_aws/storages/s3_storage.py +++ b/tc_aws/storages/s3_storage.py @@ -106,7 +106,7 @@ async def get_crypto(self, path): try: file_key = await self.storage.get(crypto_path) except ClientError as err: - logger.warn("[STORAGE] s3 key not found at %s" % crypto_path) + logger.warning("[STORAGE] s3 key not found at %s" % crypto_path) return None async with file_key['Body'] as stream: @@ -143,6 +143,13 @@ async def get(self, path): file = await super(Storage, self).get(path) except BotoCoreError: return None + except ClientError as e: + # in case there is no key found we need to return None, + # so thumbor will try to cache the not existing image + if e.__class__.__name__ == 'NoSuchKey': + return None + else: + raise e async with file['Body'] as stream: return await stream.read()