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

Blob client 'from_string' method regex does not allow bucket root #1183

Closed
mcompen opened this issue Nov 9, 2023 · 6 comments
Closed

Blob client 'from_string' method regex does not allow bucket root #1183

mcompen opened this issue Nov 9, 2023 · 6 comments
Assignees
Labels
api: storage Issues related to the googleapis/python-storage API.

Comments

@mcompen
Copy link

mcompen commented Nov 9, 2023

Environment details

  • All OS types and Python versions

Steps to reproduce

Create a Blob client with the from_string method at bucket root.

Code example

from google.cloud import storage

project = "project"
credentials = "credentials"
storage_client = storage.Client(project=project, credentials=credentials)
storage.Blob.from_string(
        uri="gs://bucket_name",
        client=storage_client,
    )

Stack trace

"/Users/manu.compen/Library/Caches/pypoetry/virtualenvs/bla-py3.9/lib/python3.9/site-packages/google/cloud/aiplatform/pipeline_jobs.py", line 404, in submit
    gcs_utils.create_gcs_bucket_for_pipeline_artifacts_if_it_does_not_exist(
  File "/Users/manu.compen/Library/Caches/pypoetry/virtualenvs/bla-py3.9/lib/python3.9/site-packages/google/cloud/aiplatform/utils/gcs_utils.py", line 237, in create_gcs_bucket_for_pipeline_artifacts_if_it_does_not_exist
    pipelines_bucket = storage.Blob.from_string(
  File "/Users/manu.compen/Library/Caches/pypoetry/virtualenvs/bla-py3.9/lib/python3.9/site-packages/google/cloud/storage/blob.py", line 410, in from_string
    raise ValueError("URI scheme must be gs")
ValueError: URI scheme must be gs

I came across this (as you can see in the stacktrace) using the aiplatform package to submit a Vertex Pipeline job where you have to specify a bucket root, but I think the bug is on this side of the fence.

@product-auto-label product-auto-label bot added the api: storage Issues related to the googleapis/python-storage API. label Nov 9, 2023
@m-rath
Copy link

m-rath commented Nov 9, 2023

Same problem here. Using aiplatform.init(staging_bucket="gs://my_staging_bucket").
Or just storage.Blob.from_string("gs://my_staging_bucket"). Same Value error. Not sure how to circumvent. Thanks

@cojenco cojenco self-assigned this Nov 10, 2023
@cojenco
Copy link
Contributor

cojenco commented Nov 10, 2023

Thanks for filing. Blob.from_string is intened to get a constructor for blob object with a blob URI. The blob URI should include an object name such as gs://bucket_name/object_name

For a bucket root, it'd make more sense to use the Bucket class method Bucket.from_string. I believe this is a bug in the aiplatform where there is a misusage of Blob.from_string here. Changing to use Bucket.from_string should fix the issue. I'll go ahead and file an issue in the aiplatform repository.

@cojenco
Copy link
Contributor

cojenco commented Nov 11, 2023

I see that googleapis/python-aiplatform#2936 is already filed along with a fix googleapis/python-aiplatform#2948
Thank you @mcompen

@mcompen
Copy link
Author

mcompen commented Nov 11, 2023

Closing this as the issue is with the aiplatform package and I opened an issue there.

@mcompen mcompen closed this as completed Nov 11, 2023
@Ark-kun
Copy link

Ark-kun commented Jan 16, 2024

Blob.from_string is intened to get a constructor for blob object with a blob URI. The blob URI should include an object name such as gs://bucket_name/object_name

What is the prescribed way to get a Bucket object for a given gs:// URI that may or may not contain path?

@yan-hic
Copy link

yan-hic commented Feb 6, 2024

What is the prescribed way to get a Bucket object for a given gs:// URI that may or may not contain path?

See here - the same method exists for Bucket

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: storage Issues related to the googleapis/python-storage API.
Projects
None yet
Development

No branches or pull requests

5 participants