google-api-python-client
google-api-python-client copied to clipboard
backupRuns().list does not generate pages correctly for large result sets
When I try to get a list of created backups, I get different results. The number of records differs if they are returned all in one request and if they are divided into pages. When comparing the results, in the current example, the first record disappeared in each new window. But this behavior occurs if there are more than two windows.
Environment details
- OS type and version: macOS Sonoma 14.4.1 (23E224)
- Python version: 3.11.6
- pip version: 24.0
google-api-python-clientversion: 2.127.0
Steps to reproduce
Run the below code
Code example
from googleapiclient import discovery
project_id = "<project_id>"
sql_api = discovery.build("sqladmin", "v1", cache_discovery=False)
request = sql_api.backupRuns().list(project=project_id, instance="-", maxResults=100)
page = request.execute()
backups = page.get("items", [])
print(f"All in one transaction. Total records: {len(backups)}")
backups = []
next_page = {}
while True:
request = sql_api.backupRuns().list(project=project_id, instance="-", maxResults=10, **next_page)
page = request.execute()
items = page.get("items", [])
print(f"transaction {next_page}. records: {len(items)}")
backups.extend(items)
next_page = page.get("nextPageToken", 0)
if next_page:
next_page = {"pageToken": next_page}
else:
break
print(f"Multiple transactions. Total records: {len(backups)}")
Stack trace
All in one transaction. Total records: 49
transaction {}. records: 10
transaction {'pageToken': '1715713200000'}. records: 10
transaction {'pageToken': '1715547600000'}. records: 10
transaction {'pageToken': '1715374800000'}. records: 10
transaction {'pageToken': '1712929640988'}. records: 5
Multiple transactions. Total records: 45
for different maxResults I get different results. for 20 the result is
All in one transaction. Total records: 49
Multiple transactions. Total records: 48
for 25 the result is
All in one transaction. Total records: 49
Multiple transactions. Total records: 49
Thanks!