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 19, 2023
1 parent d8dbadf commit c783232
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions temba/archives/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,20 +189,24 @@ def iter_records(self, *, where: dict = None):

if where:
bucket, key = self.get_storage_location()
response = s3_client.select_object_content(
Bucket=bucket,
Key=key,
ExpressionType="SQL",
Expression=s3.compile_select(where=where),
InputSerialization={"CompressionType": "GZIP", "JSON": {"Type": "LINES"}},
OutputSerialization={"JSON": {"RecordDelimiter": "\n"}},
)

def generator():
for record in EventStreamReader(response["Payload"]):
yield record

return generator()
if bucket == "":
return

else:
response = s3_client.select_object_content(
Bucket=bucket,
Key=key,
ExpressionType="SQL",
Expression=s3.compile_select(where=where),
InputSerialization={"CompressionType": "GZIP", "JSON": {"Type": "LINES"}},
OutputSerialization={"JSON": {"RecordDelimiter": "\n"}},
)

def generator():
for record in EventStreamReader(response["Payload"]):
yield record

return generator()

else:
bucket, key = self.get_storage_location()
Expand Down

0 comments on commit c783232

Please sign in to comment.