Fix KeyError when configuring S3 backups on empty buckets#2548
Open
kevinl95 wants to merge 2 commits intomail-in-a-box:mainfrom
Open
Fix KeyError when configuring S3 backups on empty buckets#2548kevinl95 wants to merge 2 commits intomail-in-a-box:mainfrom
kevinl95 wants to merge 2 commits intomail-in-a-box:mainfrom
Conversation
… contents a KeyError is not received when configuring backups.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes a minor issue I ran into when setting up backups. I created a brand new S3 bucket and intended to have my backups be stored at the top level. I got a 500 internal service error when submitting my configuration using the form on the admin panel, so I investigated syslog and discovered this error:
I put together this fix:
Problem: Configuration fails with
KeyError: 'Contents'when setting up backups on empty S3 bucketsRoot cause: list_objects_v2 doesn't return Contents key when bucket/prefix is empty
Fix: Use .get('Contents', []) to handle empty buckets gracefully
Testing: Used my version of backup.py to configure S3 backups with an empty bucket without an internal error.