Skip to content

Conversation

@chandra-siri
Copy link
Collaborator

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Fixes #<issue_number_goes_here> 🦕

@product-auto-label product-auto-label bot added size: m Pull request size is medium. api: storage Issues related to the googleapis/python-storage API. labels Jan 13, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @chandra-siri, 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 introduces the capability to perform XML Multipart Uploads (MPU) for Google Cloud Storage objects. This new feature allows for breaking down large files into smaller, manageable parts that can be uploaded concurrently, offering a more robust and potentially faster upload experience. It enhances the flexibility of the upload process by supporting file-like objects as data sources and provides a configurable option to choose between XML MPU and traditional resumable uploads.

Highlights

  • XML Multipart Upload (MPU) Implementation: Introduced a new mechanism for uploading large files using XML Multipart Upload, providing an alternative to resumable uploads. This allows for more efficient and flexible handling of data streams.
  • Flexible Data Source for XML MPU Parts: The XMLMPUPart class now supports uploading directly from a file-like object (file_obj) in addition to a filename, enhancing its versatility for various data sources.
  • Concurrent Part Uploads: Implemented parallel uploading of file chunks using ThreadPoolExecutor within the _do_xml_multipart_upload method, significantly improving the performance of large file uploads.
  • Conditional Upload Strategy: Added a perform_xml_mpu flag to the _do_upload method, enabling dynamic selection between XML Multipart Upload and the existing resumable upload strategy.
  • Metadata to Header Translation: A new helper function _headers_from_metadata was added to translate object metadata into appropriate HTTP headers for upload requests.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

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 introduces changes to support XML Multipart Uploads (MPU) from file-like objects and adds a new XML MPU upload path in the Blob class, seemingly for comparison against resumable uploads. While the changes to XMLMPUPart to accept a file_obj are a good addition, the implementation within blob.py contains several issues. There are debugging print statements, incorrect comments, and most critically, the main upload logic in _do_upload has been replaced with benchmarking code that is not production-ready. My review includes several suggestions to clean up the code and a critical comment to address the benchmarking implementation before this can be merged.

container.register_part(part_num, etag)

part_number += len(chunk_batch)
print("num parts uploaded:", part_number - 1)
Copy link
Contributor

Choose a reason for hiding this comment

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

high

This print statement appears to be for debugging. It should be removed from production code. Consider using the logging module if this information is valuable for diagnostics.

print("num parts uploaded:", part_number - 1)

res = container.finalize(transport)
print("MPU Complete Response:", res)
Copy link
Contributor

Choose a reason for hiding this comment

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

high

This print statement appears to be for debugging. It should be removed from production code. Consider using the logging module if this information is valuable for diagnostics.

Comment on lines +1306 to +1308
if (filename is None and file_obj is None) or (
filename is not None and file_obj is not None
):
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This condition can be simplified for better readability. A more Pythonic way to express that exactly one of filename or file_obj must be provided is if (filename is None) == (file_obj is None):.

import time
import base64
from concurrent.futures import ThreadPoolExecutor
import concurrent.futures
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This import is redundant. ThreadPoolExecutor is already imported from concurrent.futures on the previous line, and concurrent.futures itself is not used directly in this file. You can remove this line.

"storageClass": "x-goog-storage-class",
}

XML_CHUNK_SIZE = 100 * 1024 * 1024 # 8 MiB
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The comment here is incorrect. 100 * 1024 * 1024 is 100 MiB, not 8 MiB. Please update the comment to reflect the correct size.

Suggested change
XML_CHUNK_SIZE = 100 * 1024 * 1024 # 8 MiB
XML_CHUNK_SIZE = 100 * 1024 * 1024 # 100 MiB

Comment on lines +1926 to +1945
"""
1. This should initialize XMLMPUContainer, container.initate(), you can keep filename as None.
2. read chunks of data from stream, read at most `n` chunks (even if the file_stream is more, hold the stream there)
Where each `chunk_size` is provided as `XML_CHUNK_SIZE`
3. Spawn multiple threads to upload each chunk using
part = XMLMPUPart()
part.upload() ->
each part upload should return (part_number, etag)
store these part numbers in a list/dictionary
using `container.register_part(part_number, etag)`
4. read further chunks from stream and repeat step 3 until stream is exhausted
5. Once all parts are uploaded, call
`container.finalize(blob._get_transport(client))`
to complete the multipart upload
"""
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The docstring for this method appears to be a set of implementation notes. It should be converted into a proper docstring that explains what the method does, its parameters (file_obj, retry, content_type, num_of_threads), and what it returns. This will improve maintainability and make the code easier to understand for other developers.

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: m Pull request size is medium.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant