409 cloud protocol_error ai_generated true

409 Conflict: There is currently a lease on the blob 'container/blob.txt'. No lease ID was specified in the request.

ID: cloud/azure-storage-blob-lease-conflict-while-deleting

Also available as: JSON · Markdown · 中文
92%Fix Rate
86%Confidence
1Evidence
2023-07-20First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
azure_cli active
storage_sdk active
blob_service active

Root Cause

The blob has an active lease (e.g., infinite or finite) that must be released or specified in the delete request, but the operation attempted to delete without providing the lease ID.

generic

中文

Blob 具有活动租约(例如,无限期或有限期),必须在删除请求中释放或指定租约 ID,但操作尝试删除时未提供租约 ID。

Official Documentation

https://learn.microsoft.com/en-us/rest/api/storageservices/lease-blob

Workarounds

  1. 95% success Break the lease first using Azure CLI: `az storage blob lease break --account-name mystorageaccount --container-name container --name blob.txt --lease-break-period 30`. Then delete: `az storage blob delete --account-name mystorageaccount --container-name container --name blob.txt`
    Break the lease first using Azure CLI: `az storage blob lease break --account-name mystorageaccount --container-name container --name blob.txt --lease-break-period 30`. Then delete: `az storage blob delete --account-name mystorageaccount --container-name container --name blob.txt`
  2. 90% success In code (Python SDK), get the lease ID and delete: `from azure.storage.blob import BlobClient; blob = BlobClient.from_connection_string(conn_str, container_name="container", blob_name="blob.txt"); lease = blob.acquire_lease(); blob.delete_blob(lease=lease)`
    In code (Python SDK), get the lease ID and delete: `from azure.storage.blob import BlobClient; blob = BlobClient.from_connection_string(conn_str, container_name="container", blob_name="blob.txt"); lease = blob.acquire_lease(); blob.delete_blob(lease=lease)`

中文步骤

  1. Break the lease first using Azure CLI: `az storage blob lease break --account-name mystorageaccount --container-name container --name blob.txt --lease-break-period 30`. Then delete: `az storage blob delete --account-name mystorageaccount --container-name container --name blob.txt`
  2. In code (Python SDK), get the lease ID and delete: `from azure.storage.blob import BlobClient; blob = BlobClient.from_connection_string(conn_str, container_name="container", blob_name="blob.txt"); lease = blob.acquire_lease(); blob.delete_blob(lease=lease)`

Dead Ends

Common approaches that don't work:

  1. 80% fail

    If the lease is infinite (never expires), waiting won't help; you must break it explicitly.

  2. 90% fail

    The portal also requires lease ID for leased blobs; it will show the same error.