Skip to content

Commit e80a36d

Browse files
committed
Fix pagination bug
1 parent 0bbcb67 commit e80a36d

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

polygon/rest/base.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,9 @@ def _paginate_iter(
207207
result_key: str = "results",
208208
options: Optional[RequestOptionBuilder] = None,
209209
):
210+
limit = params.get("limit")
211+
yielded_count = 0
212+
210213
while True:
211214
resp = self._get(
212215
path=path,
@@ -226,8 +229,11 @@ def _paginate_iter(
226229
if result_key not in decoded:
227230
return []
228231
for t in decoded[result_key]:
232+
if limit is not None and yielded_count >= limit:
233+
return
229234
yield deserializer(t)
230-
if "next_url" in decoded:
235+
yielded_count += 1
236+
if "next_url" in decoded and (limit is None or yielded_count < limit):
231237
path = decoded["next_url"].replace(self.BASE, "")
232238
params = {}
233239
else:

0 commit comments

Comments
 (0)