GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Storage: Bucket.list_blobs(max_results=n) does not behave as documented · Issue #19 · googleapis/python-storage

This repository was archived by the owner on Mar 31, 2026. It is now read-only.
This repository was archived by the owner on Mar 31, 2026. It is now read-only.

Storage: Bucket.list_blobs(max_results=n) does not behave as documented #19

Copy link
Copy link
Closed
#43
Closed
Storage: Bucket.list_blobs(max_results=n) does not behave as documented#19
#43
Copy link
Labels
api: storageIssues related to the googleapis/python-storage API.priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Description

@bz2
bz2
opened on Jan 2, 2020
Issue body actions

The max_results parameter of list_blobs() is documented as controlling the maximum number of blobs returned in each page of results, but actually limits the total number of results as the name implies.

Compare the Bucket.list_blobs() documentation:
https://googleapis.dev/python/storage/latest/buckets.html#google.cloud.storage.bucket.Bucket.list_blobs

max_results (int) – The maximum number of blobs in each page of results from this request. Non-positive values are ignored. Defaults to a sensible value set by the API.

With the Iterator documentation:
https://googleapis.dev/python/google-api-core/latest/page_iterator.html#google.api_core.page_iterator.Iterator

max_results (int) – The maximum number of results to fetch.

Also the implementation of HTTPIterator which is used by list_blobs() internally does treat max_results as a hard limit for total num_results:
https://github.com/googleapis/google-cloud-python/blob/master/api_core/google/api_core/page_iterator.py#L378

Code example

iterator = some_big_bucket.list_blobs(max_results=100)
assert len(list(iterator)) > 100  # throws
assert sum(len(list(page)) for page in iterator.pages) > 100  # throws

Suggested resolution

Change the documentation to match what the parameter actually does. If supplying a paging size is required, a new argument to HTTPIterator could be added and exposed up through the list_blobs() interface.

Activity

  1. HemangChothani
    self-assigned this
    on Jan 3, 2020
  2. crwilcox
    transferred this issue fromgoogleapis/google-cloud-pythonon Jan 31, 2020
  3. product-auto-label
    added
    api: storageIssues related to the googleapis/python-storage API.
    on Jan 31, 2020
  4. yoshi-automation
    added
    triage meI really want to be triaged.
    🚨This issue needs some love.
    on Feb 3, 2020
  5. JesseLovelace
    added
    priority: p1Important issue which blocks shipping the next release. Will be fixed prior to next release.
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    and removed
    triage meI really want to be triaged.
    on Feb 4, 2020
  6. yoshi-automation
    added
    🚨This issue needs some love.
    and removed
    🚨This issue needs some love.
    on Feb 4, 2020
  7. frankyn
    added
    priority: p2Moderately-important priority. Fix may not be included in next release.
    and removed
    priority: p1Important issue which blocks shipping the next release. Will be fixed prior to next release.
    on Feb 11, 2020
  8. yoshi-automation
    removed
    🚨This issue needs some love.
    on Feb 11, 2020
  9. frankyn commented on Feb 11, 2020

    @frankyn
    frankyn
    on Feb 11, 2020
    Contributor
    More actions

    Hi folks,

    I dug into the Page iterator and found that max_results is strict in the total number of results to retrieve. However, I think there's a usability issue here in the case you want to limit the number of items per page while retrieving all items.

    Given the expectation is set in the code, moving forward with the PR that exists makes sense for now because it would require adding support for this path.

    The workaround for this is the following:

    from google.cloud import storage
    
    storage_client = storage.Client()
    bucket = storage_client.bucket("bucket-name")
    
    blobs = bucket.list_blobs(max_results=3)
    start = False
    while blobs.next_page_token or start is False:
       for blob in blobs:
           print(blob.name)
       blobs = bucket.list_blobs(max_results=3, page_token=blobs.next_page_token)
       start = True

    @crwilcox this is a usability issue because it doesn't fully expose the GCS API behavior when setting maxResults.

  10. frankyn
    closed this as completedin #43on Feb 11, 2020
  11. frankyn
    unassigned
    HemangChothani
    on Apr 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    api: storageIssues related to the googleapis/python-storage API.priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.