feat(storage): support returning skipped items as UserWarning in download_many_to_path by chandra-siri · Pull Request #1773 · googleapis/python-storage
Summary of Changes
Hello, 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 significantly improves the download_many_to_path function by making its behavior more transparent when certain files are not downloaded. Instead of simply omitting skipped items from the results, the function now returns a comprehensive list that includes UserWarning objects for each item that was not downloaded, whether due to path traversal security concerns or the skip_if_exists flag. This change provides callers with clear, actionable feedback on the status of every requested download, enhancing debugging and user experience.
Highlights
- Enhanced Return Value for Skipped Downloads: The
download_many_to_pathfunction now returns a list that includesUserWarningobjects for items that were skipped, providing explicit feedback instead of silently omitting them. - Improved Error/Warning Handling: Items skipped due to path traversal issues or
skip_if_exists=True(when the file already exists) are now explicitly represented byUserWarninginstances in the returned list. - Updated Function Signature and Internal Logic: The return type annotation for
download_many_to_pathwas updated to reflect the possibility ofUserWarningobjects. The internal call todownload_manynow consistently usesskip_if_exists=Falseas the skipping logic is handled upstream withindownload_many_to_path. - Comprehensive Test Coverage: New and updated system and unit tests were added to thoroughly validate the new behavior, covering scenarios with successful downloads,
skip_if_existswarnings, and path traversal warnings.
Changelog
- google/cloud/storage/transfer_manager.py
- Modified
download_many_to_pathto returnUserWarningobjects for items skipped due to path traversal orskip_if_exists=True. - Updated the return type annotation of
download_many_to_pathto includeUserWarning. - Adjusted the internal call to
download_manyto always useskip_if_exists=False, as the skipping logic is now handled withindownload_many_to_path.
- Modified
- tests/system/test_transfer_manager.py
- Updated
test_download_many_to_path_skips_downloadto assert that aUserWarningis returned for skipped items. - Added
test_download_many_to_path_mixed_resultsto verify the function's behavior with a mix of successful downloads,skip_if_existswarnings, and path traversal warnings.
- Updated
- tests/unit/test_transfer_manager.py
- Modified
test_download_many_to_pathto assert that the results match the mocked return value. - Added
test_download_many_to_path_with_skip_if_existsto specifically test theskip_if_existsfunctionality and the return ofUserWarning. - Updated
test_download_many_to_path_skips_downloadto assert that aUserWarningis returned for skipped items. - Modified
test_download_many_to_path_downloads_within_dest_dirto assert that the results match the mocked return value.
- Modified
Activity
- The pull request was authored by chandra-siri.
- The PR description clearly states the intent: "This PR updates download_many_to_path in transfer_manager.py to return a list of length len(blob_names) containing UserWarning objects for items skipped due to path traversal or skip_if_exists=True, as requested."
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.
-
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. ↩