Skip to content

Commit 7281bbb

Browse files
committed
Ensure operations are cleared when we bulk_run
1 parent f3a1092 commit 7281bbb

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

batch_mailchimp/batches_api.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import json
22
from io import BytesIO
33
import tarfile
4-
from itertools import islice
54
from mailchimp_marketing.api import batches_api
65
import requests
76
from .decorators import no_batch
@@ -110,13 +109,14 @@ def run(self):
110109

111110
@no_batch
112111
def bulk_run(self):
113-
if len(self.api_client.operations) == 0:
112+
if self.api_client.operations == []:
114113
raise Exception("No operations to run")
115-
operations = iter(self.api_client.operations)
116-
while operations_chunk := list(islice(operations, self._max_operations)):
114+
while self.api_client.operations:
115+
operations_chunk = self.api_client.operations[:self._max_operations]
117116
batch_data = self.start({"operations": operations_chunk})
118117
batch = Batch(self, operations=operations_chunk, **batch_data)
119118
self._batches[batch.batch_id] = batch
119+
self.api_client.operations = self.api_client.operations[self._max_operations:]
120120
return self._batches
121121

122122
def delete_all(self, refresh=False, **kwargs):

0 commit comments

Comments
 (0)