Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

batch deletions on azure / limited to 256 - Closes #509 #508

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# cloudpathlib Changelog

## Unreleased

- Fixed `rmtree` fail on Azure with no `hns` and more than 256 blobs to drop

## v0.21.0 (2025-03-03)

- Removed support for deprecated env var that had a typo (`CLOUPATHLIB_FILE_CACHE_MODE`; you should use `CLOUDPATHLIB_FILE_CACHE_MODE`).
Expand Down
8 changes: 5 additions & 3 deletions cloudpathlib/azure/azblobclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from http import HTTPStatus
from pathlib import Path
from typing import Any, Callable, Dict, Iterable, Optional, Tuple, Union
from itertools import islice

try:
from typing import cast
Expand Down Expand Up @@ -437,11 +438,12 @@ def _remove(self, cloud_path: AzureBlobPath, missing_ok: bool = True) -> None:
_hns_rmtree(self.data_lake_client, cloud_path.container, cloud_path.blob)
return

blobs = [
blobs = (
b.blob for b, is_dir in self._list_dir(cloud_path, recursive=True) if not is_dir
]
)
container_client = self.service_client.get_container_client(cloud_path.container)
container_client.delete_blobs(*blobs)
while batch := tuple(islice(blobs, 256)):
container_client.delete_blobs(*batch)
elif file_or_dir == "file":
blob = self.service_client.get_blob_client(
container=cloud_path.container, blob=cloud_path.blob
Expand Down
10 changes: 10 additions & 0 deletions tests/test_azure_specific.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,13 @@ def test_adls_gen2_rename(azure_gen2_rig):
p2 = p.rename(azure_gen2_rig.create_cloud_path("dir2"))
assert not p.exists()
assert p2.exists()


def test_batched_rmtree_no_hns(azure_rig):
p = azure_rig.create_cloud_path("new_dir")

p.mkdir()
for i in range(400):
(p / f"{i}.txt").write_text("content")
p.rmtree()
assert not p.exists()
Loading