Skip to content

Delete retention of a non-current blob fails #2980

@niriak

Description

@niriak

Environment details

Maven Artefact: com.google.cloud:google-cloud-storage:2.49.0
OS Type: Linux (Manjaro)
Java version: openjdk version "21.0.6" 2025-01-21

Steps to reproduce

  1. Create a bucket with versioning and object retention enabled
  2. Create a blob with retention in unlocked mode
  3. Delete the blob (live -> non-current)
  4. Delete the non-current blobs retention

Code example

Expected code to delete the non-current blobs retention:

var blobId = BlobId.of("my-bucket", "my-blob-name", 1741083479142854L);
var blob = storage.get(blobId, Storage.BlobGetOption.generationMatch());

var newblob = blob.toBuilder().setRetention(null).build();
newblob.update(Storage.BlobTargetOption.overrideUnlockedRetention(true), Storage.BlobTargetOption.generationMatch());

Stack trace

com.google.cloud.storage.StorageException: No such object: my-bucket/my-blob-name

	at com.google.cloud.storage.StorageException.translate(StorageException.java:209)
	at com.google.cloud.storage.spi.v1.HttpStorageRpc.translate(HttpStorageRpc.java:360)
	at com.google.cloud.storage.spi.v1.HttpStorageRpc.patch(HttpStorageRpc.java:718)
	at com.google.cloud.storage.StorageImpl.lambda$update$18(StorageImpl.java:592)
	at com.google.api.gax.retrying.DirectRetryingExecutor.submit(DirectRetryingExecutor.java:102)
	at com.google.cloud.RetryHelper.run(RetryHelper.java:76)
	at com.google.cloud.RetryHelper.runWithRetries(RetryHelper.java:50)
	at com.google.cloud.storage.Retrying.run(Retrying.java:65)
	at com.google.cloud.storage.StorageImpl.run(StorageImpl.java:1611)
	at com.google.cloud.storage.StorageImpl.update(StorageImpl.java:590)
	at com.google.cloud.storage.Blob.update(Blob.java:855)
        [...]

Any additional information below

Expected behavior:
The code example deletes the blobs retention.

Actual behavior:
The code fails with an exception, stating the non-current blob is not found

Working workaround:
It looks like the generation information is not send in the update call by default. Marking the blobId generation field as changed seems to force the generation information to be submitted, at least in the current version of the maven artefact.

var newblob = blob.toBuilder().setBlobId(/* trigger a change to the generation */ BlobId.of(blobId.getBucket(), blobId.getName())).setBlobId(/* set generation to the correct one */ blobId).setRetention(null).build();
newblob.update(Storage.BlobTargetOption.overrideUnlockedRetention(true), Storage.BlobTargetOption.generationMatch());

Let me know if you need any more information.

Metadata

Metadata

Assignees

Labels

api: storageIssues related to the googleapis/java-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