Skip to content

Commit

Permalink
Merge pull request #2584 from activeloopai/fy_azure_fix
Browse files Browse the repository at this point in the history
[AL-2411] Fix Azure download of empty blobs
  • Loading branch information
FayazRahman authored Sep 8, 2023
2 parents ce8fad9 + b86f9df commit 980308d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions deeplake/core/storage/azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand Down
9 changes: 9 additions & 0 deletions deeplake/core/storage/tests/test_storage_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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""
)

0 comments on commit 980308d

Please sign in to comment.