From f087721b7b20ad28ded1d0a84756a8bbaa2bb95a Mon Sep 17 00:00:00 2001 From: Frank Natividad Date: Wed, 4 Dec 2024 16:15:54 -0800 Subject: [PATCH] fix(storage): disable soft delete policy using 0 retentionDurationSeconds (#11226) --- storage/bucket.go | 6 ++++-- storage/bucket_test.go | 5 ++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/storage/bucket.go b/storage/bucket.go index 5601357c9b2b..43161f783825 100644 --- a/storage/bucket.go +++ b/storage/bucket.go @@ -1341,8 +1341,10 @@ func (ua *BucketAttrsToUpdate) toRawBucket() *raw.Bucket { } if ua.SoftDeletePolicy != nil { if ua.SoftDeletePolicy.RetentionDuration == 0 { - rb.NullFields = append(rb.NullFields, "SoftDeletePolicy") - rb.SoftDeletePolicy = nil + rb.SoftDeletePolicy = &raw.BucketSoftDeletePolicy{ + RetentionDurationSeconds: 0, + ForceSendFields: []string{"RetentionDurationSeconds"}, + } } else { rb.SoftDeletePolicy = ua.SoftDeletePolicy.toRawSoftDeletePolicy() } diff --git a/storage/bucket_test.go b/storage/bucket_test.go index 06cec765905d..f1bd45e52775 100644 --- a/storage/bucket_test.go +++ b/storage/bucket_test.go @@ -479,7 +479,10 @@ func TestBucketAttrsToUpdateToRawBucket(t *testing.T) { } got = au3.toRawBucket() want = &raw.Bucket{ - NullFields: []string{"RetentionPolicy", "Encryption", "Logging", "Website", "SoftDeletePolicy"}, + NullFields: []string{"RetentionPolicy", "Encryption", "Logging", "Website"}, + SoftDeletePolicy: &raw.BucketSoftDeletePolicy{ + ForceSendFields: []string{"RetentionDurationSeconds"}, + }, } if msg := testutil.Diff(got, want); msg != "" { t.Error(msg)