Skip to content

Commit de4dfb3

Browse files
Merge pull request stitchdata#8 from stitchdata/zero_division_error
fix ZeroDivisionError when no records exist to push
2 parents 8e17271 + fde9264 commit de4dfb3

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

stitchclient/client.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,19 @@ def _take_batch(self, min_records):
151151
self._buffer.clear()
152152
return result
153153

154+
154155
def _send_batch(self, batch):
155156
for body, callback_args in partition_batch(batch, self.max_batch_size_bytes):
156157
self._send(body, callback_args)
157158

158-
self.target_messages_per_batch = min(self.max_messages_per_batch,
159-
0.8 * (self.max_batch_size_bytes / self.moving_average_bytes_per_record()))
159+
try:
160+
moving_average = self.moving_average_bytes_per_record()
161+
self.target_messages_per_batch = \
162+
min(self.max_messages_per_batch,
163+
0.8 * (self.max_batch_size_bytes / moving_average))
164+
except ZeroDivisionError:
165+
# Handle the case where there are no records
166+
pass
160167

161168

162169
def _stitch_request(self, body):

0 commit comments

Comments
 (0)