thumbor-community / aws

Thumbor AWS extensions
MIT License
155 stars 70 forks source link

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

Open logart opened 1 year ago

logart commented 1 year ago

Hi there,

we had an issue while using tc_aws in our thumbor 7.5.0 set up.

The issue is it fails with 500 when file is not in s3. However I've configured it to use HttpLoader to cache not existing files.

While investigating the issue I've found out that it fails with

  result = await self._fetch(self.context.request.image_url)
  File "/usr/local/lib/python3.11/site-packages/thumbor/handlers/__init__.py", line 212, in get_image
2023-07-20 14:35:27 botocore.hooks:DEBUG Event needs-retry.s3.GetObject: calling handler <bound method S3RegionRedirector.redirect_from_error of <botocore.utils.S3RegionRedirector object at 0x7f32752e1250>>
2023-07-20 14:35:27 thumbor:ERROR [BaseHandler] get_image failed for url `external_url`. error: `An error occurred (NoSuchKey) when calling the GetObject operation: Unknown` 
2023-07-20 14:35:27 botocore.retryhandler:DEBUG No retry needed.

and code is cathing the BotoCoreError.

I've assumed that something has changed in the error handling or some other issue occured in this code block.

What I did is try to also catch NoSuchKey error. This solved the issue and now my thumbor works fine.

I would like to contribute this to the upstream so anyone who can also experience this issue will benefit from the patch.

I am not a python guru so if there is anything I could fix about my code just let me know and I would happily do it.

Wish you a great day, Artem

r0bdiabl0 commented 8 months ago

I am having this issue as well. This patch solves this. Can we merge in please?