Title: list_blobs() iterator.prefixes returns empty when API response contains prefixes
Issue Description
When using list_blobs() with a prefix and delimiter to list "directories" in a GCS bucket, the .prefixes property of the returned iterator is empty even though the raw API response shows that prefixes exist.
Reproduction Steps
Here's a complete example using the public bucket gcp-public-data-landsat:
fromgoogle.cloudimportstorageimportlogging# Set up logging to see API responseslogging.basicConfig(level=logging.DEBUG)
logger=logging.getLogger(__name__)
# Initialize client and bucketclient=storage.Client()
bucket=client.bucket('gcp-public-data-landsat')
prefix="LC08/"# This prefix exists in the landsat bucketdelimiter="/"# First show that the raw API response contains prefixeslogger.debug("\nChecking raw API response:")
page=bucket.list_blobs(prefix=prefix, delimiter=delimiter)._get_next_page_response()
logger.debug(f"Raw API response: {page}") # Shows prefixes exist# Now demonstrate that iterator.prefixes is emptylogger.debug("\nTrying to iterate prefixes:")
iterator=bucket.list_blobs(prefix=prefix, delimiter=delimiter)
prefix_count=0forprefixiniterator.prefixes:
prefix_count+=1logger.debug(f"Found prefix: {prefix}")
logger.debug(f"Total prefixes found: {prefix_count}") # Shows 0# Also demonstrate list() returns emptyprefixes=list(iterator.prefixes)
logger.debug(f"List of prefixes: {prefixes}") # Shows []Expected Behavior
The iterator's .prefixes property should provide access to the prefixes returned in the API response
Both iterating through iterator.prefixes and calling list(iterator.prefixes) should return the prefixes
Actual Behavior
The raw API response shows prefixes exist: {'kind': 'storage#objects', 'prefixes': [...]}
However, iterator.prefixes appears empty when iterated
list(iterator.prefixes) returns an empty list
Workaround
Currently using direct access to the API response as a workaround:
pythonCopypage = bucket.list_blobs(prefix=prefix, delimiter=delimiter)._get_next_page_response()
prefixes = page.get('prefixes', [])
Environment
google-cloud-storage version: 2.18.2
Python version: Python 3.11.6
OS: Darwin 23.6.0
Related Issues
#436
#483
This issue was co-authored by Claude.
Title: list_blobs() iterator.prefixes returns empty when API response contains prefixes
Issue Description
When using
list_blobs()with a prefix and delimiter to list "directories" in a GCS bucket, the.prefixesproperty of the returned iterator is empty even though the raw API response shows that prefixes exist.Reproduction Steps
Here's a complete example using the public bucket
gcp-public-data-landsat:Expected Behavior
The iterator's .prefixes property should provide access to the prefixes returned in the API response
Both iterating through iterator.prefixes and calling list(iterator.prefixes) should return the prefixes
Actual Behavior
The raw API response shows prefixes exist: {'kind': 'storage#objects', 'prefixes': [...]}
However, iterator.prefixes appears empty when iterated
list(iterator.prefixes) returns an empty list
Workaround
Currently using direct access to the API response as a workaround:
pythonCopypage = bucket.list_blobs(prefix=prefix, delimiter=delimiter)._get_next_page_response()
prefixes = page.get('prefixes', [])
Environment
google-cloud-storage version: 2.18.2
Python version: Python 3.11.6
OS: Darwin 23.6.0
Related Issues
#436
#483
This issue was co-authored by Claude.