Skip to content

Commit

Permalink
Add condition to ignore empty bucket
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaslinhares committed Dec 21, 2023
1 parent d8dbadf commit cbc7020
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions temba/archives/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()

Expand All @@ -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,
Expand All @@ -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"])

Expand Down

0 comments on commit cbc7020

Please sign in to comment.