Skip to content

storage: SoftDeletePolicy is not getting disabled on bucket creation #10380

Closed

Description

@dominikmueller

Client

Storage v1.42.0

Environment

local machine (MB Pro) (also tested in golang:alpine container)

Go Environment

$ go version
go version go1.22.4 darwin/arm64

Code

package main

import (
	"context"
	"log"
	"time"

	"cloud.google.com/go/storage"
)

const (
	BucketName = "<BUCKET_NAME>"
	ProjectID  = "<PROJECT_ID>"
)

func main() {
	ctx := context.Background()

	// Create a client
	client, err := storage.NewClient(ctx)
	if err != nil {
		log.Fatalf("Failed to create client: %v", err)
	}

	// Create the bucket
	err = client.Bucket(BucketName).Create(ctx, ProjectID, &storage.BucketAttrs{
		Location: "EU",
		SoftDeletePolicy: &storage.SoftDeletePolicy{
			// Setting the RetentionDuration to 0 should disable the feature
			RetentionDuration: 0,
		},
	})

	if err != nil {
		log.Fatalf("Failed to create bucket: %v", err)
	}
}

Expected behavior

Bucket gets created without a SoftDeletePolicy / SoftDelete Protection as mentioned in the docs:
https://github.com/googleapis/google-cloud-go/blob/storage/v1.42.0/storage/bucket.go#L491-L492

In order to fully disable soft delete, you need to set a policy with a RetentionDuration of 0.

Actual behavior

Bucket has the default 7 day soft delete policy set.

Screenshots

image

Additional context

Using any other valid RetentionDuration - e.g. 10 days using 10 * 24 * time.hour - is working as expected and sets the SoftDelete Policy to a 10 day retention duration.

Without knowing much about the internal behaviours of the golang storage lib, I would first suspect these lines when looking at the PR that implements the SoftDeletePolicy: https://github.com/googleapis/google-cloud-go/blob/main/storage/bucket.go#L1334-L1336
(But this could also be totally wrong and the issue could be caused by something completely different)

Activity

  1. added
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    priority: p2Moderately-important priority. Fix may not be included in next release.
    and removed
    triage meI really want to be triaged.
    on Jun 17, 2024
  2. tritone commented on Jun 17, 2024

    @tritone
    Contributor

    Thanks for the well-researched issue. I was able to reproduce the problem; it looks like the call works as expected for the gRPC API while failing for JSON. I am going to work on a fix.

  3. added a commit that references this issue on Jun 18, 2024
    04b6d43
  4. added a commit that references this issue on Jun 19, 2024
    d8bd2c1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

api: storageIssues related to the Cloud Storage API.priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    ⌂ 换网址