From 1a33ad9a56c09892b12194b7cb8615b2739386ad Mon Sep 17 00:00:00 2001 From: Jeff Scudder Date: Tue, 31 Mar 2026 14:11:55 -0700 Subject: [PATCH] fix: auto-created GCS staging bucket names are less predictable PiperOrigin-RevId: 892532325 --- google/cloud/aiplatform/utils/gcs_utils.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/google/cloud/aiplatform/utils/gcs_utils.py b/google/cloud/aiplatform/utils/gcs_utils.py index ac7812c9b3..7d5540e585 100644 --- a/google/cloud/aiplatform/utils/gcs_utils.py +++ b/google/cloud/aiplatform/utils/gcs_utils.py @@ -17,6 +17,7 @@ import datetime import glob +import uuid # Version detection and compatibility layer for google-cloud-storage v2/v3 from importlib.metadata import version as get_version @@ -59,6 +60,8 @@ stacklevel=2, ) +_DEFAULT_STAGING_BUCKET_SALT = str(uuid.uuid4()) + def blob_from_uri(uri: str, client: storage.Client) -> storage.Blob: """Create a Blob from a GCS URI, compatible with v2 and v3. @@ -201,9 +204,14 @@ def stage_local_data_in_gcs( # Currently we only do this when staging_gcs_dir is not specified. # The buckets that we create are regional. # This prevents errors when some service required regional bucket. - # E.g. "FailedPrecondition: 400 The Cloud Storage bucket of `gs://...` is in location `us`. It must be in the same regional location as the service location `us-central1`." - # We are making the bucket name region-specific since the bucket is regional. - staging_bucket_name = project + "-vertex-staging-" + location + # E.g. "FailedPrecondition: 400 The Cloud Storage bucket of `gs://...` + # is in location `us`. It must be in the same regional location as the + # service location `us-central1`." + # We are making the bucket name region-specific since the bucket is + # regional. + staging_bucket_name = ( + project + "-vertex-staging-" + location + "-" + _DEFAULT_STAGING_BUCKET_SALT + )[:63] client = storage.Client(project=project, credentials=credentials) staging_bucket = storage.Bucket(client=client, name=staging_bucket_name) if not staging_bucket.exists():