Skip to content

Commit a9bc7fe

Browse files
committed
Merge pull request #862 from dhermes/fix-blob-exists
Making Blob.exists() work as Bucket.exists().
2 parents d134452 + bf8b655 commit a9bc7fe

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

gcloud/storage/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def list_buckets(project=None, max_results=None, page_token=None, prefix=None,
126126
# class has it as a reserved property.
127127
if page_token is not None:
128128
result.next_page_token = page_token
129-
return iter(result)
129+
return result
130130

131131

132132
def get_bucket(bucket_name, connection=None):

gcloud/storage/blob.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,14 @@ def exists(self, connection=None):
226226
# We only need the status code (200 or not) so we seek to
227227
# minimize the returned payload.
228228
query_params = {'fields': 'name'}
229+
# We intentionally pass `_target_object=None` since fields=name
230+
# would limit the local properties.
229231
connection.api_request(method='GET', path=self.path,
230232
query_params=query_params,
231-
_target_object=self)
233+
_target_object=None)
234+
# NOTE: This will not fail immediately in a batch. However, when
235+
# Batch.finish() is called, the resulting `NotFound` will be
236+
# raised.
232237
return True
233238
except NotFound:
234239
return False

0 commit comments

Comments
 (0)