Skip to content

Commit 8ea7903

Browse files
nogatesclaude
andcommitted
Also stop cursor pagination when next cursor is missing
If the response omits the next-cursor field (or returns it empty/null), there is no way to fetch a further page, so the loop should terminate even when the current page still has results. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent edecc77 commit 8ea7903

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

.generator/src/generator/templates/api_client.j2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ class ApiClient:
354354
for item in results:
355355
yield item
356356
if "cursor_param" in pagination:
357-
if len(results) == 0:
357+
if len(results) == 0 or not get_attribute_from_path(response, pagination["cursor_path"], default=""):
358358
break
359359
elif len(results) < pagination["limit_value"]:
360360
break
@@ -659,7 +659,7 @@ class AsyncApiClient(ApiClient):
659659
for item in results:
660660
yield item
661661
if "cursor_param" in pagination:
662-
if len(results) == 0:
662+
if len(results) == 0 or not get_attribute_from_path(response, pagination["cursor_path"], default=""):
663663
break
664664
elif len(results) < pagination["limit_value"]:
665665
break

src/datadog_api_client/api_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ def call_api_paginated(
361361
for item in results:
362362
yield item
363363
if "cursor_param" in pagination:
364-
if len(results) == 0:
364+
if len(results) == 0 or not get_attribute_from_path(response, pagination["cursor_path"], default=""):
365365
break
366366
elif len(results) < pagination["limit_value"]:
367367
break
@@ -667,7 +667,7 @@ async def call_api_paginated(
667667
for item in results:
668668
yield item
669669
if "cursor_param" in pagination:
670-
if len(results) == 0:
670+
if len(results) == 0 or not get_attribute_from_path(response, pagination["cursor_path"], default=""):
671671
break
672672
elif len(results) < pagination["limit_value"]:
673673
break

0 commit comments

Comments
 (0)