Skip to content
This repository was archived by the owner on Mar 31, 2026. It is now read-only.
This repository was archived by the owner on Mar 31, 2026. It is now read-only.

bucket.delete(force=True) does not work if versioning is enabled #1071

@irigon

Description

@irigon

Environment details

  • OS type and version: Alpine Linux
  • Python version: python --version: Python 3.11.4
  • pip version: pip --version: pip 23.1.2 from /opt/venv-azcli/lib/python3.11/site-packages/pip (python 3.11)
  • google-cloud-storage version: pip show google-cloud-storage: 2.10.0

Steps to reproduce

Create a versioned bucket
Add some data
Exclude bucket forcefully.

While it would be expected that all blobs are deleted and the bucket excluded, it returns 409.

Code example

storage_client = storage.Client(credentials=mycredentials,project=myproject)
bucket_name = 'sa-bk3-hec42-cis-tmp'
bucket = storage_client.create_bucket(bucket_name, location="EUROPE-WEST4")
bucket.versioning_enabled = True
bucket.patch()

blob = storage.Blob(name=f"wrapper/test", bucket=bucket)
blob.upload_from_string(data='decomission', content_type="text/plain")

bucket = storage_client.get_bucket(bucket_name)
bucket.delete(force=True)

Stack trace

(<class 'google.api_core.exceptions.Conflict'>, Conflict('DELETE https://storage.googleapis.com/storage/v1/b/sa-bk3-hec42-cis-tmp?prettyPrint=false: The bucket you tried to delete is not empty.'), <traceback object at 0x102c416c0>)

Expected Result

According to the documentation, If force=True is passed, this will first attempt to delete all the objects / blobs in the bucket (i.e. try to empty the bucket).
Besides, 409 should indicates that the bucket name is not available. This error number seems to be misleading.

Metadata

Metadata

Assignees

Labels

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