From 0996619c9dc54ddece3b69157fe1a39881401146 Mon Sep 17 00:00:00 2001 From: Xiaoxi Fu <49707495+xiafu-msft@users.noreply.github.com> Date: Wed, 12 Aug 2020 15:57:39 -0700 Subject: [PATCH] [Storage][Blob][Batch]Support batch delete empty blob list (#13029) --- .../azure/storage/blob/_container_client.py | 3 +++ .../azure/storage/blob/aio/_container_client_async.py | 3 +++ sdk/storage/azure-storage-blob/tests/test_container.py | 7 ++++++- .../azure-storage-blob/tests/test_container_async.py | 5 +++++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/sdk/storage/azure-storage-blob/azure/storage/blob/_container_client.py b/sdk/storage/azure-storage-blob/azure/storage/blob/_container_client.py index 09fe729db1d6..35b25eaa7d46 100644 --- a/sdk/storage/azure-storage-blob/azure/storage/blob/_container_client.py +++ b/sdk/storage/azure-storage-blob/azure/storage/blob/_container_client.py @@ -1186,6 +1186,9 @@ def delete_blobs(self, *blobs, **kwargs): :dedent: 8 :caption: Deleting multiple blobs. """ + if len(blobs) == 0: + return iter(list()) + reqs, options = self._generate_delete_blobs_options(*blobs, **kwargs) return self._batch_send(*reqs, **options) diff --git a/sdk/storage/azure-storage-blob/azure/storage/blob/aio/_container_client_async.py b/sdk/storage/azure-storage-blob/azure/storage/blob/aio/_container_client_async.py index 77c65356729b..6217e9958478 100644 --- a/sdk/storage/azure-storage-blob/azure/storage/blob/aio/_container_client_async.py +++ b/sdk/storage/azure-storage-blob/azure/storage/blob/aio/_container_client_async.py @@ -952,6 +952,9 @@ async def delete_blobs( # pylint: disable=arguments-differ :dedent: 12 :caption: Deleting multiple blobs. """ + if len(blobs) == 0: + return iter(list()) + reqs, options = self._generate_delete_blobs_options(*blobs, **kwargs) return await self._batch_send(*reqs, **options) diff --git a/sdk/storage/azure-storage-blob/tests/test_container.py b/sdk/storage/azure-storage-blob/tests/test_container.py index 850e295541d3..5aed3b93b7bf 100644 --- a/sdk/storage/azure-storage-blob/tests/test_container.py +++ b/sdk/storage/azure-storage-blob/tests/test_container.py @@ -25,7 +25,7 @@ PremiumPageBlobTier, generate_container_sas, PartialBatchErrorException, - generate_account_sas, ResourceTypes, AccountSasPermissions) + generate_account_sas, ResourceTypes, AccountSasPermissions, ContainerClient) #------------------------------------------------------------------------------ TEST_CONTAINER_PREFIX = 'container' @@ -1073,6 +1073,11 @@ def test_list_blobs_with_delimiter(self, resource_group, location, storage_accou self.assertNamedItemInContainer(resp, 'b/') self.assertNamedItemInContainer(resp, 'blob4') + def test_batch_delete_empty_blob_list(self): + container_client = ContainerClient("https://mystorageaccount.blob.core.windows.net", "container") + blob_list = list() + container_client.delete_blobs(*blob_list) + @pytest.mark.skipif(sys.version_info < (3, 0), reason="Batch not supported on Python 2.7") @GlobalStorageAccountPreparer() def test_delete_blobs_simple(self, resource_group, location, storage_account, storage_account_key): diff --git a/sdk/storage/azure-storage-blob/tests/test_container_async.py b/sdk/storage/azure-storage-blob/tests/test_container_async.py index 6f18efd86421..dece7ecb6e01 100644 --- a/sdk/storage/azure-storage-blob/tests/test_container_async.py +++ b/sdk/storage/azure-storage-blob/tests/test_container_async.py @@ -1149,6 +1149,11 @@ async def test_list_blobs_with_delimiter(self, resource_group, location, storage self.assertNamedItemInContainer(resp, 'b/') self.assertNamedItemInContainer(resp, 'blob4') + def test_batch_delete_empty_blob_list(self): + container_client = ContainerClient("https://mystorageaccount.blob.core.windows.net", "container") + blob_list = list() + container_client.delete_blobs(*blob_list) + @GlobalStorageAccountPreparer() @AsyncStorageTestCase.await_prepared_test async def test_delete_blobs_simple(self, resource_group, location, storage_account, storage_account_key):