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

Closed
jdimatteo opened this issue Oct 1, 2020 · 1 comment
Closed

Blob upload_from_string AttributeError when using client argument #286

jdimatteo opened this issue Oct 1, 2020 · 1 comment

Comments

@jdimatteo
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 google.cloud import storage
from google.cloud.storage.blob 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(
            "gs://jdimatteo-gunk/example/upload_from_string_error/workaround_1.txt",
            client=storage_client)
    blob.upload_from_string("workaround_1\n")

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
    blob.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
@jdimatteo
Copy link
Author

@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
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

3 participants