409 cloud protocol_error ai_generated true

409 Conflict: The object version you are trying to delete is not the latest version.

ID: cloud/gcp-cloud-storage-bucket-object-versioning-conflict

Also available as: JSON · Markdown · 中文
95%Fix Rate
90%Confidence
1Evidence
2023-08-20First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
GCS JSON API v1 active
Google Cloud Storage Client Library 2.x active
gsutil 5.x active

Root Cause

When bucket versioning is enabled, deleting a non-latest object version requires specifying the generation number; otherwise Cloud Storage returns a 409 conflict.

generic

中文

当存储桶启用版本控制时,删除非最新对象版本需要指定代次编号,否则Cloud Storage返回409冲突。

Official Documentation

https://cloud.google.com/storage/docs/deleting-objects#delete-object-noncurrent

Workarounds

  1. 95% success Use gsutil with generation number: `gsutil rm gs://bucket-name/object#<generation-number>`. To find generation numbers: `gsutil ls -la gs://bucket-name/object`.
    Use gsutil with generation number: `gsutil rm gs://bucket-name/object#<generation-number>`. To find generation numbers: `gsutil ls -la gs://bucket-name/object`.
  2. 98% success Delete all versions of an object: `gsutil rm -a gs://bucket-name/object` (the -a flag removes all versions).
    Delete all versions of an object: `gsutil rm -a gs://bucket-name/object` (the -a flag removes all versions).

中文步骤

  1. Use gsutil with generation number: `gsutil rm gs://bucket-name/object#<generation-number>`. To find generation numbers: `gsutil ls -la gs://bucket-name/object`.
  2. Delete all versions of an object: `gsutil rm -a gs://bucket-name/object` (the -a flag removes all versions).

Dead Ends

Common approaches that don't work:

  1. 95% fail

    If bucket versioning is enabled, the API requires generation for deleting a specific version; the error persists.

  2. 70% fail

    Disabling versioning does not delete existing versions; you must suspend versioning and then delete each version separately.

  3. 85% fail

    gsutil rm without -a only deletes the live version; non-current versions remain and cause conflict errors.