Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backupRuns().list does not generate pages correctly for large result sets #2403

Open
ve4eslav opened this issue May 16, 2024 · 0 comments
Open
Assignees

Comments

@ve4eslav
Copy link

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-client version: 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!

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

No branches or pull requests

2 participants