From cbc7020ccb34967e05320a575f762b300b9521a1 Mon Sep 17 00:00:00 2001 From: lucaslinhares Date: Fri, 15 Dec 2023 18:11:16 -0300 Subject: [PATCH] Add condition to ignore empty bucket --- temba/archives/models.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/temba/archives/models.py b/temba/archives/models.py index 740e1110c7a..5e0f40a90ea 100644 --- a/temba/archives/models.py +++ b/temba/archives/models.py @@ -114,7 +114,7 @@ def get_download_link(self): if self.url: s3_client = s3.client() bucket, key = self.get_storage_location() - if bucket == "": + if not bucket: return "" s3_params = { "Bucket": bucket, @@ -175,8 +175,11 @@ def iter_all_records( def generator(): for archive in archives: - for record in archive.iter_records(where=where): - yield record + try: + for record in archive.iter_records(where=where): + yield record + except TypeError: + pass return generator() @@ -186,9 +189,12 @@ def iter_records(self, *, where: dict = None): """ s3_client = s3.client() + bucket, key = self.get_storage_location() + + if not bucket: + return if where: - bucket, key = self.get_storage_location() response = s3_client.select_object_content( Bucket=bucket, Key=key, @@ -205,7 +211,6 @@ def generator(): return generator() else: - bucket, key = self.get_storage_location() s3_obj = s3_client.get_object(Bucket=bucket, Key=key) return jsonlgz_iterate(s3_obj["Body"])