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 · Fixed by #290
Closed

Blob upload_from_string AttributeError when using client argument #286

jdimatteo opened this issue Oct 1, 2020 · 1 comment · Fixed by #290
Assignees
Labels
api: storage Issues related to the googleapis/python-storage API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@jdimatteo
Copy link

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
@product-auto-label product-auto-label bot added the api: storage Issues related to the googleapis/python-storage API. label Oct 1, 2020
@jdimatteo
Copy link
Author

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.

@yoshi-automation yoshi-automation added triage me I really want to be triaged. 🚨 This issue needs some love. labels Oct 2, 2020
@HemangChothani HemangChothani added type: question Request for information or clarification. Not an issue. and removed 🚨 This issue needs some love. triage me I really want to be triaged. labels Oct 8, 2020
@HemangChothani HemangChothani self-assigned this Oct 8, 2020
@HemangChothani HemangChothani added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. and removed type: question Request for information or clarification. Not an issue. labels Oct 8, 2020
cojenco pushed a commit to cojenco/python-storage that referenced this issue Oct 13, 2021
cojenco pushed a commit to cojenco/python-storage that referenced this issue Oct 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: storage Issues related to the googleapis/python-storage API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
3 participants