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.
| user_project: user_project, | ||
| delete_source_objects: delete_source_objects |
There was a problem hiding this comment.
Since the Google Cloud Storage JSON API does not support deleting source objects during a compose operation, this feature must be implemented client-side. After a successful compose call, we should iterate over the source files and delete them.
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| if_generation_match: nil, | ||
| if_metageneration_match: nil, | ||
| user_project: nil, | ||
| delete_source_objects: nil, |
There was a problem hiding this comment.
The Google Cloud Storage JSON API's ComposeRequest does not support a delete_source_objects field. Passing this parameter to Google::Apis::StorageV1::ComposeRequest.new will result in an ArgumentError: unknown keyword: :delete_source_objects at runtime. Please remove this parameter from the service layer, as the deletion of source objects must be handled client-side in the bucket layer.
| compose_req = Google::Apis::StorageV1::ComposeRequest.new source_objects: source_objects, | ||
| destination: destination_gapi | ||
| destination: destination_gapi, | ||
| delete_source_objects: delete_source_objects |
|
|
||
|
|
||
| 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 |
| source_objects: source_objects, | ||
| delete_source_objects: delete_source_objects |
| it "can compose a new file with delete_source_objects option" do | ||
| mock = Minitest::Mock.new | ||
| req = compose_request [file_gapi, file_2_gapi], delete_source_objects: true | ||
| mock.expect :compose_object, file_3_gapi, [bucket.name, file_3_name, req], **compose_object_args(options: {retries: 0}) | ||
|
|
||
| bucket.service.mocked_service = mock | ||
|
|
||
| new_file = bucket.compose [file, file_2], file_3_name, delete_source_objects: true | ||
| _(new_file).must_be_kind_of Google::Cloud::Storage::File | ||
| _(new_file.name).must_equal file_3_name | ||
|
|
||
| mock.verify | ||
| end |
There was a problem hiding this comment.
Since delete_source_objects is now implemented client-side, the unit test needs to mock the delete_object calls on the service for each source file being deleted.
it "can compose a new file with delete_source_objects option" do
mock = Minitest::Mock.new
req = compose_request [file_gapi, file_2_gapi]
mock.expect :compose_object, file_3_gapi, [bucket.name, file_3_name, req], **compose_object_args(options: {retries: 0})
mock.expect :delete_object, nil, [bucket.name, file.name], **compose_object_args(options: {})
mock.expect :delete_object, nil, [bucket.name, file_2.name], **compose_object_args(options: {})
bucket.service.mocked_service = mock
new_file = bucket.compose [file, file_2], file_3_name, delete_source_objects: true
_(new_file).must_be_kind_of Google::Cloud::Storage::File
_(new_file.name).must_equal file_3_name
mock.verify
end
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>