Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Making Blob.exists() work as Bucket.exists(). #862

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

Merged
merged 1 commit into from
May 7, 2015

Conversation

dhermes
Copy link
Contributor

@dhermes dhermes commented May 6, 2015

Also returning the _BucketIterator directly in
storage.api.list_buckets() rather than wrapping it in iter().

@tseaver As mentioned #812 (comment) I said I'd fix Blob.exists() while making sure the iterators didn't work in batches.

It turns out they were already not working. Here is a working get request

>>> from gcloud import _helpers
>>> from gcloud import storage
>>> 
>>> _helpers._PROJECT_ENV_VAR_NAME = 'GCLOUD_TESTS_PROJECT_ID'
>>> storage.set_defaults()
>>>
>>> with storage.Batch() as batch:
...     bucket = storage.get_bucket('bucket-name')
...     print bucket._properties
... 
<gcloud.storage.batch._FutureDict object at 0x7f7ce19f4a10>
>>> bucket._properties
{u'kind': u'storage#bucket', u'name': u'bucket-name', ...

while a bucket iterator fails since _FutureDict.get throws a KeyError:

>>> with storage.Batch() as batch:
...     buckets_iter = storage.list_buckets()
...     response = buckets_iter.get_next_page_response()
... 
Traceback (most recent call last):
  File "<stdin>", line 3, in <module>
  File "gcloud/storage/iterator.py", line 115, in get_next_page_response
    self.next_page_token = response.get('nextPageToken')
  File "gcloud/storage/batch.py", line 96, in get
    key, default))
KeyError: "Cannot get('nextPageToken', default=None) on a future"

and a blob iterator fails (but not quite always)

>>> bucket.connection
<gcloud.storage.batch.Batch object at 0x7f3b1c56db50>
>>> bucket.connection._connection
<gcloud.storage.connection.Connection object at 0x7f3b1c56d490>
>>> bucket._connection = None
>>>
>>> with storage.Batch() as batch:
...     blobs_iter = bucket.list_blobs()
...     response = blobs_iter.get_next_page_response()
...
Traceback (most recent call last):
  File "<stdin>", line 3, in <module>
  File "gcloud/storage/iterator.py", line 111, in get_next_page_response
    response = self.connection.api_request(
AttributeError: 'NoneType' object has no attribute 'api_request'

Also returning the _BucketIterator directly in
storage.api.list_buckets() rather than wrapping it in iter().
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label May 6, 2015
@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling bf8b655 on dhermes:fix-blob-exists into aafcd2a on GoogleCloudPlatform:master.

@tseaver
Copy link
Contributor

tseaver commented May 7, 2015

LGTM

dhermes added a commit that referenced this pull request May 7, 2015
Making Blob.exists() work as Bucket.exists().
@dhermes dhermes merged commit a9bc7fe into googleapis:master May 7, 2015
@dhermes dhermes deleted the fix-blob-exists branch May 7, 2015 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.