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

Add try-except block to guard against NotFound exception from GCS delete #31603

Merged
merged 2 commits into from
Jun 15, 2024
Merged
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
13 changes: 12 additions & 1 deletion sdks/python/apache_beam/io/gcp/gcsio_integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@
except ImportError:
gcsio = None # type: ignore

try:
from google.api_core.exceptions import NotFound
except ImportError:
NotFound = None


@unittest.skipIf(gcsio is None, 'GCP dependencies are not installed')
class GcsIOIntegrationTest(unittest.TestCase):
Expand Down Expand Up @@ -145,6 +150,7 @@ def test_batch_copy_and_delete(self):

@pytest.mark.it_postcommit
@mock.patch('apache_beam.io.gcp.gcsio.default_gcs_bucket_name')
@unittest.skipIf(NotFound is None, 'GCP dependencies are not installed')
def test_create_default_bucket(self, mock_default_gcs_bucket_name):
google_cloud_options = self.test_pipeline.options.view_as(
GoogleCloudOptions)
Expand All @@ -168,7 +174,12 @@ def test_create_default_bucket(self, mock_default_gcs_bucket_name):
# remove the existing bucket with the same name as the default bucket
existing_bucket = self.gcsio.get_bucket(overridden_bucket_name)
if existing_bucket:
existing_bucket.delete()
try:
existing_bucket.delete()
except NotFound:
# Bucket existence check from get_bucket may be inaccurate due to gcs
# cache or delay
pass

bucket = gcsio.get_or_create_default_gcs_bucket(google_cloud_options)
self.assertIsNotNone(bucket)
Expand Down
Loading