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

Catch forbidden errors as notfound #33148

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions sdks/python/apache_beam/io/gcp/gcsio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method that is failing exists() [1], which calls _gcs_object().

The Forbidden error mentions it can be a permission issue or the bucket does not exist. So we might swallow actual permission issues too.

I think we can list the buckets with a prefix to check for existence explicitly.

client.list_buckets(prefix=bucket_name)

[1]

def exists(self, path):

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, you're right about it being exists, I added it there as well.

The Forbidden error mentions it can be a permission issue or the bucket does not exist. So we might swallow actual permission issues too.

I think this is going to be true even if we do what you're suggesting. If there are permissions issues, the bucket won't show up in our list call either

return None

def create_bucket(
Expand Down Expand Up @@ -410,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):
Expand Down
Loading