Skip to content

Conversation

@rcleveng
Copy link
Contributor

@rcleveng rcleveng commented Nov 9, 2025

fix(bucket): url encode new_name parameter in move_blob()

The move_blob() method was not URL encoding the new_name parameter
before passing it to the API call, unlike how the blob encodes its own
path. This caused failures when moving blobs to paths with special
characters.

Added URL encoding for new_name to match the blob path encoding, as
both names must fit in the API URL format: "{blob_path}/moveTo/o/{new_name}"

Here's an example of what fails:

from google.cloud import storage
gcs = storage.Client()
bucket = gcs.bucket("")
blob = bucket.get_blob("test/blob.csv")
bucket.move_blob(
    blob, 
    new_name="test/blob2.csv"
)

Fixes #1523

There's no need to add a test when the name does not need urlencoding
since that's already covered in the previous 2 tests for move_blob.
@rcleveng rcleveng requested review from a team as code owners November 9, 2025 22:10
@product-auto-label product-auto-label bot added the size: s Pull request size is small. label Nov 9, 2025
@product-auto-label product-auto-label bot added the api: storage Issues related to the googleapis/python-storage API. label Nov 9, 2025
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @rcleveng, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical bug in the Google Cloud Storage client library's Bucket#move_blob() function. Previously, attempts to move blobs to a new name containing special characters that required URL encoding would result in an error. The implemented fix ensures that the new_name is properly URL-encoded before constructing the API request path, thereby preventing these failures and significantly improving the robustness and reliability of blob movement operations for a wider array of object names.

Highlights

  • Bug Fix: Resolves an issue where Bucket#move_blob() failed when the target blob name contained characters that required URL encoding.
  • URL Encoding: The new_name parameter in the move_blob method is now explicitly URL-encoded using the _quote utility before being used in the API request path.
  • Test Coverage: A new unit test, test_move_blob_needs_url_encoding, has been added to verify the correct URL encoding behavior for blob move operations.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly fixes a bug in Bucket.move_blob() where the new blob name was not being URL-encoded, causing failures for names containing special characters like '/'. The fix involves using the existing _quote helper to encode the new_name before constructing the API request path. A new unit test, test_move_blob_needs_url_encoding, has been added to verify this fix and prevent future regressions. The changes are correct, well-tested, and I approve of them.

@rcleveng rcleveng changed the title Move blob fails when the new blob name contains characters that need to be url encoded fix(bucket): Move blob fails when the new blob name contains characters that need to be url encoded Nov 10, 2025
@rcleveng
Copy link
Contributor Author

Hey @chandra-siri is there anything else I need to do here on this one?

Copy link
Contributor

@chandra-siri chandra-siri left a comment

Choose a reason for hiding this comment

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

LGTM.

@chandra-siri
Copy link
Contributor

Hey @chandra-siri is there anything else I need to do here on this one?

  1. You need to update the branch and resolve conflicts, if any.
  2. Add systems tests in tests/system/test_bucket.py (you can raise a separate PR , or we'll do it in couple of days)

Thanks for fixing this issue.

@chandra-siri
Copy link
Contributor

@rcleveng I've reviewed it now. Thanks for your patience and apologies for the delay.

@chandra-siri chandra-siri added the kokoro:run Add this label to force Kokoro to re-run the tests. label Nov 18, 2025
@yoshi-kokoro yoshi-kokoro removed the kokoro:run Add this label to force Kokoro to re-run the tests. label Nov 18, 2025
@chandra-siri chandra-siri added the owlbot:run Add this label to trigger the Owlbot post processor. label Nov 18, 2025
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Nov 18, 2025
@chandra-siri chandra-siri merged commit ec470a2 into googleapis:main Nov 18, 2025
15 of 16 checks passed
@chandra-siri
Copy link
Contributor

Hi @rcleveng

No additional action required. I've merged this PR and raised PR for system tests as well. #1624

chandra-siri added a commit that referenced this pull request Nov 26, 2025
Sys test for move blob.

Add System test for bukect.move_blob where blob name needs url encoding.
The fix was done in
#1605
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. size: s Pull request size is small.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bucket.move_blob not working with url encoded chars in blob name

5 participants