Skip to content

Storage#update always removes all lifecycle rules if they are not specified #850

Closed
@sisidra

Description

@sisidra

Issue with com.google.cloud.storage.Storage#update(com.google.cloud.storage.BucketInfo, com.google.cloud.storage.Storage.BucketTargetOption...)

Expected behaviour:

update only fields that are specified in BucketInfo parameter.

Actual behaviour:

along the updated fields, removes lifecycle rules if they are not specified.

Example code:

    val bucketId = "[...]"

    val client = StorageOptions.getDefaultInstance.getService
    val before = client.get(bucketId)
    println(s"Before: ${before.getLifecycleRules.size()}")

    val updateRequest = BucketInfo
      .newBuilder(bucketId)
      .setLabels(singletonMap("test", "test"))
      .build
    client.update(updateRequest)

    val after = client.get(bucketId)
    println(s"After: ${after.getLifecycleRules.size()}")

Actual output (for bucket with 1 lifecycle rule):

Before: 1
After: 0

I suspect that issue is located here:

Set<Rule> rules = new HashSet<>();
if (deleteRules != null) {
rules.addAll(
transform(
deleteRules,
new Function<DeleteRule, Rule>() {
@Override
public Rule apply(DeleteRule deleteRule) {
return deleteRule.toPb();
}
}));
}
if (lifecycleRules != null) {
rules.addAll(
transform(
lifecycleRules,
new Function<LifecycleRule, Rule>() {
@Override
public Rule apply(LifecycleRule lifecycleRule) {
return lifecycleRule.toPb();
}
}));
}
if (rules != null) {
Lifecycle lifecycle = new Lifecycle();
lifecycle.setRule(ImmutableList.copyOf(rules));
bucketPb.setLifecycle(lifecycle);
}

Metadata

Metadata

Assignees

Labels

api: storageIssues related to the googleapis/java-storage API.priority: p1Important issue which blocks shipping the next release. Will be fixed prior to 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