Skip to content
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.

Blob upload_from_string AttributeError when using client argument #286

Description

@jdimatteo

Environment details

  • OS type and version: variant of Debian Linux
  • Python version: 3.8.5
  • pip version: 20.1.1
  • google-cloud-storage version: 1.31.2

Steps to reproduce

  1. create Blob object using from_string without a specified client
  2. use Blobupload_from_string with client argument

Code example

fromgoogle.cloudimportstoragefromgoogle.cloud.storage.blobimportBlobdefreproduce_error():
storage_client=storage.Client()
blob=Blob.from_string("gs://jdimatteo-gunk/example/upload_from_string_error/reproduce_error.txt")
blob.upload_from_string("foo", client=storage_client)
defworkaround_1():
storage_client=storage.Client()
blob=Blob.from_string(
"gs://jdimatteo-gunk/example/upload_from_string_error/workaround_1.txt",
client=storage_client)
blob.upload_from_string("workaround_1\n")
defworkaround_2():
storage_client=storage.Client()
blob=Blob.from_string("gs://jdimatteo-gunk/example/upload_from_string_error/workaround_2.txt")
blob.bucket._client=storage_clientblob.upload_from_string("workaround_2\n")
workaround_1()
workaround_2()
reproduce_error()

Stack trace

$ python example.py Traceback (most recent call last):
File "example.py", line 24, in <module>
reproduce_error()
File "example.py", line 7, in reproduce_error
blob.upload_from_string("foo", client=storage_client)
File "/usr/local/google/home/jdimatteo/gunk/upload_from_string_error_example/venv/lib/python3.8/site-packages/google/cloud/storage/blob.py", line 2440, in upload_from_string
self.upload_from_file(
File "/usr/local/google/home/jdimatteo/gunk/upload_from_string_error_example/venv/lib/python3.8/site-packages/google/cloud/storage/blob.py", line 2223, in upload_from_file
created_json = self._do_upload(
File "/usr/local/google/home/jdimatteo/gunk/upload_from_string_error_example/venv/lib/python3.8/site-packages/google/cloud/storage/blob.py", line 2055, in _do_upload
response = self._do_multipart_upload(
File "/usr/local/google/home/jdimatteo/gunk/upload_from_string_error_example/venv/lib/python3.8/site-packages/google/cloud/storage/blob.py", line 1614, in _do_multipart_upload
hostname=self.client._connection.API_BASE_URL, bucket_path=self.bucket.path
AttributeError: 'NoneType' object has no attribute '_connection'
$ gsutil cat gs://jdimatteo-gunk/example/upload_from_string_error/workaround_1.txt
workaround_1
$ gsutil cat gs://jdimatteo-gunk/example/upload_from_string_error/workaround_2.txt
workaround_2

Metadata

Metadata

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