Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
dominikmueller opened this issue Jun 14, 2024 · 1 comment · Fixed by #10394
Closed

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

dominikmueller opened this issue Jun 14, 2024 · 1 comment · Fixed by #10394
Assignees
Labels
api: storage Issues related to the Cloud Storage API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@dominikmueller
Copy link

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)

@dominikmueller dominikmueller added the triage me I really want to be triaged. label Jun 14, 2024
@product-auto-label product-auto-label bot added the api: storage Issues related to the Cloud Storage API. label Jun 15, 2024
@tritone tritone added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. priority: p2 Moderately-important priority. Fix may not be included in next release. and removed triage me I really want to be triaged. labels Jun 17, 2024
@tritone
Copy link
Contributor

tritone commented Jun 17, 2024

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.

tritone added a commit to tritone/google-cloud-go that referenced this issue Jun 18, 2024
Currently setting an empty soft delete policy to disable the
feature does not work on bucket creation (only update). This fixes
the issue by forcing the library to send a zero value in this
case (sending a null does not seem to work).

Also adds this case to the relevant integration test.

Fixes googleapis#10380
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: storage Issues related to the Cloud Storage API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants