google-cloud-php icon indicating copy to clipboard operation
google-cloud-php copied to clipboard

Give a clearer way to opt-out of `generation` specification when working with versioned GCS objects.

Open SpencerMalone opened this issue 4 years ago • 0 comments

Is your feature request related to a problem? Please describe. When you have versioning enabled on a bucket, by default any deletion request will include generation, and according to https://cloud.google.com/storage/docs/object-versioning this means Specifying the generation number in a deletion request permanently deletes the version, even if the version is live.

I found this extremely unintuitive, as the API treats generation as opt-in, but the client has generation as a difficult to find opt-out (I finally did it by using the filter option when retrieving my object before deletion).

Describe the solution you'd like I'd love a clearer way to disable specification of the generation attribute, since it has such a meaningful change on object versioning when deleting an object. In my mind, this could be a simple but explicit function or option for disabling generation on versioned objects.

Describe alternatives you've considered Alternatively, if specification of generation were opt-in, I think that would better reflect my expected behavior, but would also be a large breaking change, so I don't particularly expect it to happen.

Additional context Currently, disabling generation while doing a delete looks something like...

        // Assume $bucket is defined elsewhere
        $options = [
            // We're filtering fields to avoid the `generation` from being set when deleting, which would hard delete this object.
            // See: https://cloud.google.com/storage/docs/object-versioning#intro
            // I find this highly unintuitive, since I can't even do an exclude here, I have to filter on what I wanna include.
            'fields' => 'items/name,nextPageToken',
        ];
        foreach ($bucket->objects($options) as $object) {
            $object->delete();
        }

And you'll need to add additional fields for whatever work you are doing.

SpencerMalone avatar Sep 08 '21 18:09 SpencerMalone