Skip to content

Conversation

@AzmainMahatab
Copy link

@AzmainMahatab AzmainMahatab commented Jan 9, 2026

  • I understand that this repository is auto-generated, and my pull request may not be merged

Changes being requested

This PR fixes a critical logic bug in pagination.py that causes infinite loops when iterating over results.

The Bug:
The next_page_info iterator blindly increments the page number even when the API returns the last page's data repeatedly for out-of-bounds requests (instead of 404s).

The Fix:

  1. Updated Sync and Async paginators to strictly stop iteration when current_page >= total_pages.
  2. Updated V4PagePaginationArrayResultInfo model to include the missing total_pages, total_count, and count fields so the SDK can correctly read the metadata.

Verification:

  • Verified locally with a reproduction script against the live client.accounts.list() endpoint.
  • Added unit tests in tests/test_pagination_fix.py to verify the logic in isolation.

Additional context & links

Example codes to test:

from cloudflare import Cloudflare, AsyncCloudflare

api_token = "redacted"
cloudflare = Cloudflare(api_token=api_token)

for account in cloudflare.accounts.list():
    print(account.name)

async_cloudflare = AsyncCloudflare(api_token=api_token)

async for account in async_cloudflare.accounts.list():
    print(account .name)

It was looping indefinitely by printing the same account, but with my fix, the loop properly ends.

Note on CI:
I noticed unrelated CI failures:

  • ImportError in radar tests (circular imports upstream).
  • AuthenticationError in cloudforce_one tests (upstream mock server auth).

My specific unit tests for pagination pass, and the formatting checks are green.

@AzmainMahatab AzmainMahatab force-pushed the fix/pagination-infinite-loop branch from bc65071 to ad9a22a Compare January 9, 2026 08:40
@AzmainMahatab AzmainMahatab changed the base branch from main to next January 9, 2026 08:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant