File tree Expand file tree Collapse file tree 2 files changed +8
-6
lines changed
sdks/python/apache_beam/io/gcp Expand file tree Collapse file tree 2 files changed +8
-6
lines changed Original file line number Diff line number Diff line change @@ -481,11 +481,10 @@ def exists(self, path):
481481 Args:
482482 path: GCS file path pattern in the form gs://<bucket>/<name>.
483483 """
484- try :
485- self ._gcs_object (path )
486- return True
487- except NotFound :
488- return False
484+ bucket_name , blob_name = parse_gcs_path (path )
485+ bucket = self .client .bucket (bucket_name )
486+ blob = bucket .blob (blob_name )
487+ return blob .exists (retry = self ._storage_client_retry )
489488
490489 def checksum (self , path ):
491490 """Looks up the checksum of a GCS object.
Original file line number Diff line number Diff line change @@ -231,6 +231,9 @@ def download_as_bytes(self, **kwargs):
231231 def __eq__ (self , other ):
232232 return self .bucket .get_blob (self .name ) is other .bucket .get_blob (other .name )
233233
234+ def exists (self , ** kwargs ):
235+ return self .bucket .get_blob (self .name ) is not None
236+
234237
235238@unittest .skipIf (NotFound is None , 'GCP dependencies are not installed' )
236239class TestGCSPathParser (unittest .TestCase ):
@@ -396,7 +399,7 @@ def test_exists(self):
396399 self .assertFalse (self .gcs .exists (file_name + 'xyz' ))
397400 self .assertTrue (self .gcs .exists (file_name ))
398401
399- @mock .patch .object (FakeBucket , 'get_blob ' )
402+ @mock .patch .object (FakeBlob , 'exists ' )
400403 def test_exists_failure (self , mock_get ):
401404 # Raising an error other than 404. Raising 404 is a valid failure for
402405 # exists() call.
You can’t perform that action at this time.
0 commit comments