boto / boto3

AWS SDK for Python
https://aws.amazon.com/sdk-for-python/
Apache License 2.0
9.05k stars 1.87k forks source link

CodeBuild.Paginator.ListBuildsForProject - incorrect 'MaxItems' #4320

Open ashmeet-kandhari opened 1 week ago

ashmeet-kandhari commented 1 week ago

Describe the bug

When using paginator api for codebuild's list_builds_for_project api the response still fetches the default size which is 100 items but the iterator gives only MaxItems configured and misses the rest of them

For example if MaxItems is configured as 20 the response_iterator returns only 20 items then fetches next 100 items and returns first 20 again

response_iterator = paginator.paginate(
    projectName='string',
    sortOrder='DESCENDING',
    PaginationConfig={
        'MaxItems': 123
    }
)

Regression Issue

Expected Behavior

Maxitems should fetch only 20 items and then iterate to fetch next 20

Current Behavior

MaxItems only iterates over the configured value from the fetched list and misses the rest of them when it iterates again

Reproduction Steps

response_iterator = paginator.paginate(
    projectName='string',
    sortOrder='DESCENDING',
    PaginationConfig={
        'MaxItems': 123
    }
)

Possible Solution

No response

Additional Information/Context

No response

SDK version used

1.35.49

Environment details (OS name and version, etc.)

Mac

tim-finnigan commented 2 days ago

Thanks for reaching out. Here is the Boto3 documentation on pagination for reference: https://boto3.amazonaws.com/v1/documentation/api/latest/guide/paginators.html

It sounds like the behavior you're expecting applies to PageSize, which controls the number of items returned per page of each result. But PageSize is not supported for the ListBuildsForProject paginator.

Regarding this:

For example if MaxItems is configured as 20 the response_iterator returns only 20 items then fetches next 100 items and returns first 20 again

With this code I only get 20 items, so MaxItems is behaving as expected:

import boto3

codebuild = boto3.client('codebuild')

paginator = codebuild.get_paginator('list_builds_for_project')

response_iterator = paginator.paginate(
    projectName='test-project',
    sortOrder='DESCENDING',
    PaginationConfig={
        'MaxItems': 20,
    }
)

for page in response_iterator:
    i = 1
    for build_id in page['ids']:
        print(f"{i}build_id")
        i += 1

If you're seeing different results then please share your debug logs (with any sensitive info redacted) by adding boto3.set_stream_logger('') to your script.