From 928ca81397d73cb552685a5df29af9cec9f5b7c8 Mon Sep 17 00:00:00 2001 From: pappapisshu <39009553+pappapisshu@users.noreply.github.com> Date: Thu, 9 Feb 2023 00:22:31 +0100 Subject: [PATCH] The list_target_files() function correctly handles an empty S3 bucket. --- management/backup.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/management/backup.py b/management/backup.py index f145d2ec..8a263b86 100755 --- a/management/backup.py +++ b/management/backup.py @@ -502,8 +502,10 @@ def list_target_files(config): aws_access_key_id=config["s3_access_key_id"], \ aws_secret_access_key=config["s3_secret_access_key"]) - bucket_objects = s3.list_objects_v2(Bucket=bucket, Prefix=path)['Contents'] - backup_list = [(key['Key'][len(path):], key['Size']) for key in bucket_objects] + backup_list = [] + bucket_objects = s3.list_objects_v2(Bucket=bucket, Prefix=path) + if "Contents" in bucket_objects: + backup_list = [(key['Key'][len(path):], key['Size']) for key in bucket_objects['Contents']] except ClientError as e: raise ValueError(e) return backup_list