-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Labels
api: storageIssues related to the Cloud Storage API.Issues related to the Cloud Storage API.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.‘Nice-to-have’ improvement, new feature or different behavior or design.
Description
Currently, blob.delete and bucket.delete_blob always delete the live version on buckets with versioning enabled. Other than being a missing feature, this can also cause some very unwanted behaviour, if a new version of the object is uploaded during the process of getting and deleting an object.
--- a/blob.py
+++ b/blob.py
@@ -279,7 +279,8 @@
(propagated from
:meth:`gcloud.storage.bucket.Bucket.delete_blob`).
"""
- return self.bucket.delete_blob(self.name, client=client)
+ return self.bucket.delete_blob(self.name, self.generation,
+ client=client)
def download_to_file(self, file_obj, encryption_key=None, client=None):
"""Download the contents of this blob into a file-like object.
--- a/bucket.py
+++ b/bucket.py
@@ -357,7 +357,7 @@
client.connection.api_request(method='DELETE', path=self.path,
_target_object=None)
- def delete_blob(self, blob_name, client=None):
+ def delete_blob(self, blob_name, generation=None, client=None):
"""Deletes a blob from the current bucket.
If the blob isn't found (backend 404), raises a
@@ -392,6 +392,8 @@
"""
client = self._require_client(client)
blob_path = Blob.path_helper(self.path, blob_name)
+ if generation:
+ blob_path += '?generation=%i' % generation
# We intentionally pass `_target_object=None` since a DELETE
# request has no response value (whether in a standard request or
# in a batch request).Metadata
Metadata
Assignees
Labels
api: storageIssues related to the Cloud Storage API.Issues related to the Cloud Storage API.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.‘Nice-to-have’ improvement, new feature or different behavior or design.