Pagination on /accounts returns only one page, but has_more_pages() incorrectly returns True
@vaishakdinesh đang làm issue này rồi.
Từ ngày 30/6/2025.
Đánh giá
Issue này chưa được đánh giá.
Mô tả
Describe the bug
I created an account-scoped API token and used it to call the /accounts endpoint, expecting to retrieve a single account (as expected for an account-scoped token).
Here is the code I am using:
cloudflare_client = Cloudflare(api_token=cloudflare_integration_config.api_token)
for cloudflare_client_result in cloudflare_client.accounts.list():
...
However the loop keeps returning the same single account result repeatedly.
After debugging, I found that has_next_page() always returns True, even though there’s only one result. This causes the pagination loop to continue indefinitely.
ipdb> cloudflare_client_result
SyncV4PagePaginationArray[Account](result=[Account(id='ACCOUNT_ID', name="ACCOUNT_NAME", created_on=datetime.datetime(2023, 2, 8, 7, 11, 56, 234700, tzinfo=TzInfo(UTC)), settings=Settings(abuse_contact_email=None, default_nameservers='cloudflare.standard', enforce_twofactor=False, use_account_custom_ns_by_default=False, api_access_enabled=None, access_approval_expiry=None), type='standard', legacy_flags={'enterprise_zone_quota': {'maximum': 0, 'current': 0, 'available': 0}})], result_info=V4PagePaginationArrayResultInfo(page=1, per_page=20, total_pages=1, count=1, total_count=1), success=True, errors=[], messages=[])
ipdb> cloudflare_client_result.has_next_page()
True
UPDATE:
➜ curl -X GET "https://api.cloudflare.com/client/v4/accounts?per_page=50&page=1" \
-H "Authorization: Bearer MY_API_KEY" \
-H "Content-Type:application/json"
{"result":[{"id":"ACCOUNT_ID_1","name":"ACCOUNT_NAME_1","type":"standard","settings":{"enforce_twofactor":false,"api_access_enabled":null,"access_approval_expiry":null,"use_account_custom_ns_by_default":false,"default_nameservers":"cloudflare.standard","abuse_contact_email":null},"legacy_flags":{"enterprise_zone_quota":{"maximum":0,"current":0,"available":0}},"created_on":"2023-02-08T07:11:56.234700Z"}],"result_info":{"page":1,"per_page":50,"total_pages":1,"count":1,"total_count":1},"success":true,"errors":[],"messages":[]}%
➜ curl -X GET "https://api.cloudflare.com/client/v4/accounts?per_page=50&page=2" \
-H "Authorization: Bearer MY_API_KEY" \
-H "Content-Type:application/json"
{"result":[{"id":"ACCOUNT_ID_1","name":"ACCOUNT_NAME_1","type":"standard","settings":{"enforce_twofactor":false,"api_access_enabled":null,"access_approval_expiry":null,"use_account_custom_ns_by_default":false,"default_nameservers":"cloudflare.standard","abuse_contact_email":null},"legacy_flags":{"enterprise_zone_quota":{"maximum":0,"current":0,"available":0}},"created_on":"2023-02-08T07:11:56.234700Z"}],"result_info":{"page":2,"per_page":50,"total_pages":1,"count":1,"total_count":1},"success":true,"errors":[],"messages":[]}%
➜ curl -X GET "https://api.cloudflare.com/client/v4/accounts?per_page=50&page=3" \
-H "Authorization: Bearer MY_API_KEY" \
-H "Content-Type:application/json"
{"result":[{"id":"ACCOUNT_ID_1","name":"ACCOUNT_NAME_1","type":"standard","settings":{"enforce_twofactor":false,"api_access_enabled":null,"access_approval_expiry":null,"use_account_custom_ns_by_default":false,"default_nameservers":"cloudflare.standard","abuse_contact_email":null},"legacy_flags":{"enterprise_zone_quota":{"maximum":0,"current":0,"available":0}},"created_on":"2023-02-08T07:11:56.234700Z"}],"result_info":{"page":3,"per_page":50,"total_pages":1,"count":1,"total_count":1},"success":true,"errors":[],"messages":[]}%
It appears that the page query parameter is not functioning as described in the API documentation.
To Reproduce
- Issue an account-scoped API token from Cloudflare.
- Use the token to call the /accounts endpoint using the API client.
- Attempt to fetch all accounts and append results to a list.
- On the first (and should be the only but it's not) page of results, check has_next_page().
- Observe that has_next_page() returns True, even though there are no additional pages.
Code snippets
results = []
cloudflare_client = Cloudflare(api_token=cloudflare_integration_config.api_token)
for cloudflare_client_result in cloudflare_client.accounts.list().iter_pages():
breakpoint()
results.append(cloudflare_client_result)
pprint(results)
results = []
cloudflare_client = Cloudflare(api_token=cloudflare_integration_config.api_token)
for cloudflare_client_result in cloudflare_client.accounts.list():
pprint(cloudflare_client_result)
results.append(cloudflare_client_result)
OS
macOS 15.3.2 (24D81)
Python version
3.12.9
Library version
4.1.0
- Ngôn ngữ chính
- Python
- Star
- 509
- Fork
- 150
- Merge trung bình
- 3 giờ 15 phút
- Pull request đã merge (30 ngày)
- 1
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của cloudflare/cloudflare-python
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
cloudflare/cloudflare-python#2747 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
cloudflare/cloudflare-python#2718 · 1 bình luận ·
-
`client.pages.projects.list` returns a paginated list of `Deployment`s instead of `Project`s Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
cloudflare/cloudflare-python#2692 · 1 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
cloudflare/cloudflare-python#2679 · 4 bình luận · 5 reaction ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
cloudflare/cloudflare-python#2745 · 1 bình luận ·
Tất cả issue của cloudflare/cloudflare-python
Issue tương tự
-
triage/confirmed
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
agentscope-ai/agentscope#2775 ·
-
comp/desktop P3 type/bug
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 92/100
NousResearch/hermes-agent#118866 ·
-
bug
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
apache/cloudstack#14222 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100