fix(bucket): Move blob fails when the new blob name contains characters that need to be url encoded by rcleveng · Pull Request #1605 · googleapis/python-storage · GitHub
Skip to content
This repository was archived by the owner on Mar 31, 2026. It is now read-only.

fix(bucket): Move blob fails when the new blob name contains characters that need to be url encoded#1605

Merged
chandra-siri merged 3 commits into
googleapis:mainfrom
rcleveng:move_blob
Nov 18, 2025
Merged

fix(bucket): Move blob fails when the new blob name contains characters that need to be url encoded#1605
chandra-siri merged 3 commits into
googleapis:mainfrom
rcleveng:move_blob

Conversation

@rcleveng

@rcleveng rcleveng commented Nov 9, 2025

Copy link
Copy Markdown
Contributor

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 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
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor Author

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

@chandra-siri chandra-siri left a comment

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
Collaborator

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
Copy Markdown
Collaborator

@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
Copy Markdown
Collaborator

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
chandra-siri added a commit that referenced this pull request Dec 9, 2025
🤖 I have created a release *beep* *boop*
---


##
[3.7.0](v3.6.0...v3.7.0)
(2025-12-09)


### Features

* Auto enable mTLS when supported certificates are detected
([#1637](#1637))
([4e91c54](4e91c54))
* Send entire object checksum in the final api call of resumable upload
([#1654](#1654))
([ddce7e5](ddce7e5))
* Support urllib3 >= 2.6.0
([#1658](#1658))
([57405e9](57405e9))


### Bug Fixes

* **bucket:** Move blob fails when the new blob name contains characters
that need to be url encoded
([#1605](#1605))
([ec470a2](ec470a2))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
Co-authored-by: Chandra Shekhar Sirimala <chandrasiri@google.com>
parthea pushed a commit to googleapis/google-cloud-python that referenced this pull request Mar 9, 2026
Sys test for move blob.

Add System test for bukect.move_blob where blob name needs url encoding.
The fix was done in
googleapis/python-storage#1605
parthea pushed a commit to googleapis/google-cloud-python that referenced this pull request Mar 9, 2026
🤖 I have created a release *beep* *boop*
---


##
[3.7.0](googleapis/python-storage@v3.6.0...v3.7.0)
(2025-12-09)


### Features

* Auto enable mTLS when supported certificates are detected
([#1637](googleapis/python-storage#1637))
([4e91c54](googleapis/python-storage@4e91c54))
* Send entire object checksum in the final api call of resumable upload
([#1654](googleapis/python-storage#1654))
([ddce7e5](googleapis/python-storage@ddce7e5))
* Support urllib3 &gt;= 2.6.0
([#1658](googleapis/python-storage#1658))
([57405e9](googleapis/python-storage@57405e9))


### Bug Fixes

* **bucket:** Move blob fails when the new blob name contains characters
that need to be url encoded
([#1605](googleapis/python-storage#1605))
([ec470a2](googleapis/python-storage@ec470a2))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
Co-authored-by: Chandra Shekhar Sirimala <chandrasiri@google.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

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