support_delete_source_object#62
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a delete_source_objects option to the compose method, allowing users to automatically delete source files after composing them into a new file. However, the reviewer correctly points out that the underlying Google Cloud Storage JSON API's ComposeRequest does not support this parameter, which would cause an ArgumentError at runtime. The feedback advises implementing this deletion client-side within the bucket layer instead, and provides detailed code suggestions to update the service layer, test helpers, and unit tests accordingly.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a delete_source_objects option to the compose method in Bucket to delete source files after a successful composition. However, the reviewer pointed out a critical issue: the Google Cloud Storage JSON API does not support a deleteSourceObjects parameter, and passing it to ComposeRequest.new will raise an ArgumentError at runtime. The feedback suggests implementing the deletion client-side within Bucket#compose instead, and provides detailed guidance on how to update the implementation, unit tests, and test helpers accordingly.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| delete_source_objects: nil, | ||
| options: {} | ||
| source_objects = compose_file_source_objects source_files, if_source_generation_match | ||
| compose_req = Google::Apis::StorageV1::ComposeRequest.new source_objects: source_objects, | ||
| destination: destination_gapi | ||
| destination: destination_gapi, | ||
| delete_source_objects: delete_source_objects |
There was a problem hiding this comment.
The Google Cloud Storage JSON API's objects.compose method does not support a deleteSourceObjects parameter or option in the ComposeRequest body. Consequently, Google::Apis::StorageV1::ComposeRequest does not have a delete_source_objects attribute. Passing this parameter to ComposeRequest.new will raise an ArgumentError: unknown keyword: :delete_source_objects at runtime.
To support deleting source objects after composition, this must be implemented as a client-side operation in Bucket#compose rather than being passed to the API request.
options: {}
source_objects = compose_file_source_objects source_files, if_source_generation_match
compose_req = Google::Apis::StorageV1::ComposeRequest.new source_objects: source_objects,
destination: destination_gapi| if_source_generation_match: if_source_generation_match, | ||
| if_generation_match: if_generation_match, | ||
| if_metageneration_match: if_metageneration_match, | ||
| user_project: user_project | ||
| user_project: user_project, | ||
| delete_source_objects: delete_source_objects | ||
| File.from_gapi gapi, service, user_project: user_project | ||
| end |
There was a problem hiding this comment.
Since the GCS API does not support deleting source objects during composition, we must implement this client-side. After successfully composing the file, we should iterate over the source files and delete them using service.delete_file.
if_source_generation_match: if_source_generation_match,
if_generation_match: if_generation_match,
if_metageneration_match: if_metageneration_match,
user_project: user_project
file = File.from_gapi gapi, service, user_project: user_project
if delete_source_objects
sources.each do |source|
source_name = source.respond_to?(:name) ? source.name : source
service.delete_file name, source_name, user_project: user_project
end
end
file
end| mock.expect :compose_object, file_3_gapi do |bucket_name, dest_name, req, **options| | ||
| _(bucket_name).must_equal bucket.name | ||
| _(dest_name).must_equal file_3_name | ||
| _(req.delete_source_objects).must_equal true | ||
| file_3_gapi | ||
| end |
There was a problem hiding this comment.
Since delete_source_objects is implemented client-side, the mock should expect delete_object calls for each source file instead of expecting delete_source_objects on the ComposeRequest object.
mock.expect :compose_object, file_3_gapi do |bucket_name, dest_name, req, **options|
_(bucket_name).must_equal bucket.name
_(dest_name).must_equal file_3_name
file_3_gapi
end
mock.expect :delete_object, nil do |bucket_name, object_name, **options|
_(bucket_name).must_equal bucket.name
_(object_name).must_equal file.name
end
mock.expect :delete_object, nil do |bucket_name, object_name, **options|
_(bucket_name).must_equal bucket.name
_(object_name).must_equal file_2.name
end| Google::Apis::StorageV1::ComposeRequest.new( | ||
| destination: destination_gapi, | ||
| source_objects: source_objects | ||
| source_objects: source_objects, | ||
| delete_source_objects: delete_source_objects | ||
| ) |
There was a problem hiding this comment.
|
|
||
|
|
||
| def compose_request source_files, destination_gapi = nil, if_source_generation_match: nil | ||
| def compose_request source_files, destination_gapi = nil, if_source_generation_match: nil, delete_source_objects: nil |
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:
bundle exec rake ciin the gem subdirectory.closes: #<issue_number_goes_here>