From 2f7063b2389614736bb1adedd8d122cb7ac24a41 Mon Sep 17 00:00:00 2001 From: xiafu Date: Tue, 11 Aug 2020 01:22:20 -0700 Subject: [PATCH] [Storage][Blob][Batch]Support batch delete empty blob list --- .../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 3fbb6a07e571..bafbaac5e453 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 @@ -1187,6 +1187,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 0f15fb8b9008..6bd98db9ef57 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 9eff48fcf92f..202f8374ee9b 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' @@ -1048,6 +1048,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 dae1aa82d0b7..9feed0d5cec6 100644 --- a/sdk/storage/azure-storage-blob/tests/test_container_async.py +++ b/sdk/storage/azure-storage-blob/tests/test_container_async.py @@ -1123,6 +1123,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):