Skip to content

pagination sample code creates an infinite loop when the list contains a number of items divisible by pageSize #1843

Open
@dvmorris

Description

@dvmorris

Environment details

  • OS type and version: Linux, CentOS 7
  • Python version: 3.8.10
  • pip version: 20.2.3
  • google-api-python-client version: 2.49.0

Steps to reproduce

  1. Follow the sample pagination code here: https://googleapis.github.io/google-api-python-client/docs/pagination.html
  2. Implement this technique for the users list API, against a Cloud Identity environment that has 100, 200, 300, or 400 users (because pageSize defaults to 100... this should theoretically be reproduced with 5 users and a pageSize of 5, etc.)

Code example

    request = service.users().list(domain='*********.com', orderBy='email')
    users = []
    while request is not None:
        user_list = request.execute()
        for user in user_list['users']:
            users.append(user)
        request = service.users().list_next(request, user_list)

Output

After the first N pages of users returns from the API, the response object contains this (see below), and the code sample produces an infinite loop:

{'etag': '"SEQQBYC70u6XQ2UUjmjNYw6b0a5EzY0mTMShjiZga8A/HMFwD2wLX237BRmKZQUJYB5ZE7U"', 'kind': 'admin#directory#users'}

{'etag': '"SEQQBYC70u6XQ2UUjmjNYw6b0a5EzY0mTMShjiZga8A/HMFwD2wLX237BRmKZQUJYB5ZE7U"', 'kind': 'admin#directory#users'}

{'etag': '"SEQQBYC70u6XQ2UUjmjNYw6b0a5EzY0mTMShjiZga8A/HMFwD2wLX237BRmKZQUJYB5ZE7U"', 'kind': 'admin#directory#users'}

{'etag': '"SEQQBYC70u6XQ2UUjmjNYw6b0a5EzY0mTMShjiZga8A/HMFwD2wLX237BRmKZQUJYB5ZE7U"', 'kind': 'admin#directory#users'}

...

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: p3Desirable enhancement or fix. May not be included in next release.samplesIssues that are directly related to samples.type: docsImprovement to the documentation for an API.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions