Skip to content

support_delete_source_object#62

Closed
shubhangi-google wants to merge 5 commits into
mainfrom
support_delete_source_object
Closed

support_delete_source_object#62
shubhangi-google wants to merge 5 commits into
mainfrom
support_delete_source_object

Conversation

@shubhangi-google

Copy link
Copy Markdown
Owner

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.
  • Follow the instructions in CONTRIBUTING. Most importantly, ensure the tests and linter pass by running bundle exec rake ci in the gem subdirectory.
  • Update code documentation if necessary.

closes: #<issue_number_goes_here>

@shubhangi-google shubhangi-google marked this pull request as draft June 12, 2026 05:37

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

Copy link
Copy Markdown

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 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.

Comment thread google-cloud-storage/lib/google/cloud/storage/bucket.rb
Comment thread google-cloud-storage/lib/google/cloud/storage/service.rb
Comment thread google-cloud-storage/lib/google/cloud/storage/service.rb
Comment thread google-cloud-storage/test/helper.rb
Comment thread google-cloud-storage/test/helper.rb
@shubhangi-google shubhangi-google marked this pull request as ready for review June 15, 2026 11:11
@thiyaguk09 thiyaguk09 removed their assignment Jun 15, 2026
@thiyaguk09 thiyaguk09 self-requested a review June 15, 2026 13:04
Comment thread google-cloud-storage/test/google/cloud/storage/bucket_compose_test.rb Outdated
@shubhangi-google

Copy link
Copy Markdown
Owner Author

/gemini review

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

Copy link
Copy Markdown

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 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.

Comment on lines +552 to +557
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

critical

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

Comment on lines 2236 to 2242
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

critical

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

Comment on lines +274 to +279
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

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

Comment on lines 641 to 645
Google::Apis::StorageV1::ComposeRequest.new(
destination: destination_gapi,
source_objects: source_objects
source_objects: source_objects,
delete_source_objects: delete_source_objects
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

Revert the changes to ComposeRequest.new in the test helper since delete_source_objects is not a valid attribute of Google::Apis::StorageV1::ComposeRequest.

    Google::Apis::StorageV1::ComposeRequest.new(
      destination: destination_gapi,
      source_objects: 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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Remove the unused delete_source_objects parameter from the helper method signature.

  def compose_request source_files, destination_gapi = nil, if_source_generation_match: nil

@thiyaguk09 thiyaguk09 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants