Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blob upload_from_string AttributeError when using client argument #286

jdimatteo opened this issue Oct 1, 2020 · 1 comment

Blob upload_from_string AttributeError when using client argument #286

jdimatteo opened this issue Oct 1, 2020 · 1 comment


Copy link

@jdimatteo jdimatteo commented Oct 1, 2020

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 Blob upload_from_string with client argument

Code example

from import storage
from import Blob 

def reproduce_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)

def workaround_1():
    storage_client = storage.Client()
    blob = Blob.from_string(

def workaround_2():
    storage_client = storage.Client()
    blob = Blob.from_string("gs://jdimatteo-gunk/example/upload_from_string_error/workaround_2.txt")
    blob.bucket._client = storage_client


Stack trace

$ python 
Traceback (most recent call last):
  File "", line 24, in <module>
  File "", 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/", line 2440, in upload_from_string
  File "/usr/local/google/home/jdimatteo/gunk/upload_from_string_error_example/venv/lib/python3.8/site-packages/google/cloud/storage/", 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/", 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/", 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
$ gsutil cat gs://jdimatteo-gunk/example/upload_from_string_error/workaround_2.txt
Copy link

@jdimatteo jdimatteo commented Oct 1, 2020

Here is an example fix: jdimatteo@df00005

I haven't contributed to this project before and it would take me a little while to get up to speed on the test framework etc.

I'll create a proper pull request if nobody else gets to this before I do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

3 participants