question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

paginator PaginationConfig PageSize is used for pagination control instead of MaxItems

See original GitHub issue

If there is 20 items and we want to list 5 items per page, the paginator PaginationConfig seems using PageSize to control pagination.

Following works, “Marker” is return when there is more data to be returned, and “IsTruncated” also return True.

import sys
import boto3
iam = boto3.client("iam")
marker = None
while True:
    paginator = iam.get_paginator('list_users')
    response_iterator = paginator.paginate(
        PaginationConfig={
            'PageSize': 5,
            'StartingToken': marker})
    for page in response_iterator:
        print("Next Page : {} ".format(page['IsTruncated']))
        u = page['Users']
        for user in u:
            print(user['UserName'])
    try:
        marker = page['Marker']
        print(marker)
    except KeyError:
        sys.exit()

However, if PaginationConfig use Maxitem, e.g.

 response_iterator = paginator.paginate(
        PaginationConfig={
            'MaxItems': 5,
            'StartingToken': marker})

The list just show 5 items and stop, no Markers returns(and isTruncated return as false) as mentioned in the documentation.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

5reactions
joguSDcommented, Aug 28, 2018

Looking at the example in the original post, I think this isn’t really how we intended the pagination interface to be used. I also think there might be some confusion between the properties of a PaginationConfig and the low-level service API inputs to control pagination.

The PaginationConfig object is designed such that the field names remain the same regardless of how the API exposes them. That is MaxItems and PageSize passed to the PaginationConfig mean the same thing to every API operation. For example, the list_users operation exposes a ‘MaxItems’ input that controls what the PaginationConfig defines as PageSize. The paginator interface is designed to smooth over these inconsistencies.

The intent of MaxItems is to limit the total number of items returned across all pages. PageSize is intended to limit how many items are on a single page. While the low-level API pagination fields are in the response pages (IsTruncated and Marker) we aren’t really expecting users to be relying on those as that kind of defeats the purpose of the auto-pagination. And in a case like this, where the MaxItems setting truncated the results in the middle of the page, relying on the API outputs to determine if there are more items can lead to missing some items, or missing the rest of the items. If you want to be doing this you should use build_full_result as mentioned before which can handle truncation in the middle of an API responses’ page for you.

I think this might come down to how we communicate the expected behavior of the auto-paginators.

2reactions
kyleknapcommented, Aug 30, 2016

This seems like a bug to me, but need to do more researching. In short, it seems if MaxItems is specified and if a marker is not returned from the service API response, it will not populate the NextToken, but it should because the paginator stopped in the middle of the only page given back. Furthermore if after you call paginate() you can call build_full_result and that will get you a NextToken. So I wonder if it is just an issue with the __iter__

Read more comments on GitHub >

github_iconTop Results From Across the Web

Paginators — Boto3 Docs 1.26.32 documentation - AWS
The paginate method accepts a PaginationConfig named argument that can be used to customize the pagination: paginator = client.get_paginator('list_objects') ...
Read more >
python 3.x - How to use Boto3 pagination - Stack Overflow
1. in boto3.client.get_paginator, MaxItems seems become a data listing threshold/limiter, it is not use as paginator. You need to use PageSize ...
Read more >
paginator PaginationConfig PageSize is used ... - Bountysource
paginator PaginationConfig PageSize is used for pagination control instead of MaxItems ... If there is 20 items and we want to list 5...
Read more >
How to use the botocore.paginate.Paginator function in ... - Snyk
To help you get started, we've selected a few botocore.paginate. ... :param PaginationConfig: A dictionary that provides parameters to control pagination.
Read more >
[Example code]-How to use Boto3 pagination
paginator = client.get_paginator('list_users') response_iterator = paginator.paginate( PaginationConfig={ 'MaxItems': 1000, 'PageSize': 123}) for page in ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found