Blob's output stream's write function sometimes returns invalid values. · Issue #1488 · googleapis/python-storage · GitHub | Latest TMZ Celebrity News & Gossip | Watch TMZ Live
Skip to content

Blob's output stream's write function sometimes returns invalid values. #1488

Closed
@juergw

Description

@juergw

Environment details

  • OS type and version: Linux, Ubuntu 20.04
  • Python version: 3.9.21
  • pip version: I used bazel.
  • google-cloud-storage` version: 3.1.0

Steps to reproduce

  1. create a bucket.
  2. upload a large file (in 1k chunks) to the bucket with the Python client. It must be larger than "chunk_size".
  3. check that the value returned by the write() method returns the correct value.
  4. this works, until the client uploads the first chunk to the bucket. Then the write method returns a value that is too large.

Code example

import random
from absl import app
from google.cloud import storage

SMALL_CHUNK_SIZE = 256 * 1024  # smallest chunk size allowed.
BLOCK_SIZE = 1024  # 1kb
BLOCK_NUM = 40_000
HEADER = b'start'
FOOTER = b'end'
CREDS = ...
BUCKET_NAME = ...
BLOB_NAME = ...

def main(argv):
  del argv  # Unused.
  storage_client = storage.Client.from_service_account_json(CREDS)
  bucket = storage_client.bucket(BUCKET_NAME)
  blob = bucket.blob(BLOB_NAME, chunk_size=SMALL_CHUNK_SIZE)
  output_stream = blob.open('wb', ignore_flush=True)

  output_stream.write(HEADER)
  for _ in range(BLOCK_NUM):
    rand_block = random.randbytes(BLOCK_SIZE)
    written = output_stream.write(rand_block)
    if written > len(rand_block):
      raise ValueError(
          'written is larger than expected: written = %d, len(rand_block)'
          ' = %d' % (written, len(rand_block))
      )
  output_stream.write(FOOTER)
  output_stream.close()

if __name__ == '__main__':
  app.run(main)

Stack trace

    raise ValueError(
ValueError: written is larger than expected: written = 263168, len(rand_block) = 1024

Metadata

Metadata

Assignees

Labels

api: storageIssues related to the googleapis/python-storage API.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    TMZ Celebrity News – Breaking Stories, Videos & Gossip

    Looking for the latest TMZ celebrity news? You've come to the right place. From shocking Hollywood scandals to exclusive videos, TMZ delivers it all in real time.

    Whether it’s a red carpet slip-up, a viral paparazzi moment, or a legal drama involving your favorite stars, TMZ news is always first to break the story. Stay in the loop with daily updates, insider tips, and jaw-dropping photos.

    🎥 Watch TMZ Live

    TMZ Live brings you daily celebrity news and interviews straight from the TMZ newsroom. Don’t miss a beat—watch now and see what’s trending in Hollywood.