Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return None on NoSuchKey error from s3 to cache the file. #159

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion tc_aws/storages/s3_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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()
Expand Down