From 712b3262b5159850fffa4d2d0bee999dda0d6038 Mon Sep 17 00:00:00 2001 From: Danny McCormick Date: Mon, 18 Nov 2024 09:37:44 -0500 Subject: [PATCH 1/2] Catch forbidden errors as notfound --- sdks/python/apache_beam/io/gcp/gcsio.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sdks/python/apache_beam/io/gcp/gcsio.py b/sdks/python/apache_beam/io/gcp/gcsio.py index 22a33fa13c63..83a79d8efa27 100644 --- a/sdks/python/apache_beam/io/gcp/gcsio.py +++ b/sdks/python/apache_beam/io/gcp/gcsio.py @@ -36,6 +36,7 @@ from typing import Union from google.cloud import storage +from google.cloud.exceptions import Forbidden from google.cloud.exceptions import NotFound from google.cloud.storage.fileio import BlobReader from google.cloud.storage.fileio import BlobWriter @@ -172,7 +173,7 @@ def get_bucket(self, bucket_name, **kwargs): try: return self.client.lookup_bucket( bucket_name, retry=self._storage_client_retry, **kwargs) - except NotFound: + except (Forbidden, NotFound): return None def create_bucket( From ef477672675e49e237c256672d4dcabb1cffccd4 Mon Sep 17 00:00:00 2001 From: Danny McCormick Date: Mon, 18 Nov 2024 10:06:53 -0500 Subject: [PATCH 2/2] Add to exists --- sdks/python/apache_beam/io/gcp/gcsio.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdks/python/apache_beam/io/gcp/gcsio.py b/sdks/python/apache_beam/io/gcp/gcsio.py index 83a79d8efa27..182189a2fcd9 100644 --- a/sdks/python/apache_beam/io/gcp/gcsio.py +++ b/sdks/python/apache_beam/io/gcp/gcsio.py @@ -411,7 +411,7 @@ def exists(self, path): try: self._gcs_object(path) return True - except NotFound: + except (Forbidden, NotFound): return False def checksum(self, path):