diff --git a/deeplake/core/storage/azure.py b/deeplake/core/storage/azure.py index 10ea83887f..00635d9f73 100644 --- a/deeplake/core/storage/azure.py +++ b/deeplake/core/storage/azure.py @@ -142,6 +142,9 @@ def get_bytes( ) if not blob_client.exists(): raise KeyError(path) + # Azure raises an error when trying to download an empty blob + if blob_client.get_blob_properties().size == 0: + return b"" byts = blob_client.download_blob(offset=offset, length=length).readall() return byts @@ -342,6 +345,9 @@ def get_presigned_url(self, path: str, full: bool = False) -> str: def get_object_from_full_url(self, url: str) -> bytes: blob_client, _ = self.get_clients_from_full_path(url) + # Azure raises an error when trying to download an empty blob + if blob_client.get_blob_properties().size == 0: + return b"" return blob_client.download_blob().readall() def _check_update_creds(self, force=False): diff --git a/deeplake/core/storage/tests/test_storage_provider.py b/deeplake/core/storage/tests/test_storage_provider.py index 4ef827c1b9..b14c325cf1 100644 --- a/deeplake/core/storage/tests/test_storage_provider.py +++ b/deeplake/core/storage/tests/test_storage_provider.py @@ -220,3 +220,12 @@ def test_azure_storage_clear(azure_storage): azure_storage.clear() assert len(azure_storage) == 0 + + +def test_azure_empty_blob(azure_storage): + azure_storage["empty_blob"] = b"" + assert azure_storage["empty_blob"] == b"" + assert ( + azure_storage.get_object_from_full_url(f"{azure_storage.root}/empty_blob") + == b"" + )