Skip to content

Commit b3cee9d

Browse files
pjbullalikefia
andauthored
Live Tests: batch deletions on azure / limited to 256 - Closes #509 (#508) (#511)
* batch deletions on azure / limited to 256 - Closes #509 (#508) * batch deletions on azure / limited to 256 * test + changelog * avoid batched / compatibility * minimal diff * Update docstrings handler --------- Co-authored-by: Ali Kefia <[email protected]>
1 parent fb81872 commit b3cee9d

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

HISTORY.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# cloudpathlib Changelog
22

3+
## Unreleased
4+
5+
- Fixed `rmtree` fail on Azure with no `hns` and more than 256 blobs to drop (Issue [#509](https://github.com/drivendataorg/cloudpathlib/issues/509), PR [#508](https://github.com/drivendataorg/cloudpathlib/pull/508), thanks @alikefia)
6+
37
## v0.21.0 (2025-03-03)
48

59
- Removed support for deprecated env var that had a typo (`CLOUPATHLIB_FILE_CACHE_MODE`; you should use `CLOUDPATHLIB_FILE_CACHE_MODE`).

cloudpathlib/azure/azblobclient.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from http import HTTPStatus
55
from pathlib import Path
66
from typing import Any, Callable, Dict, Iterable, Optional, Tuple, Union
7+
from itertools import islice
78

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

440-
blobs = [
441+
blobs = (
441442
b.blob for b, is_dir in self._list_dir(cloud_path, recursive=True) if not is_dir
442-
]
443+
)
443444
container_client = self.service_client.get_container_client(cloud_path.container)
444-
container_client.delete_blobs(*blobs)
445+
while batch := tuple(islice(blobs, 256)):
446+
container_client.delete_blobs(*batch)
445447
elif file_or_dir == "file":
446448
blob = self.service_client.get_blob_client(
447449
container=cloud_path.container, blob=cloud_path.blob

requirements-dev.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ mike
1313
mkdocs>=1.2.2
1414
mkdocs-jupyter
1515
mkdocs-material>=7.2.6
16-
mkdocstrings[python-legacy]>=0.19.0
16+
mkdocstrings[python]>=0.19.0
1717
mypy
1818
nbautoexport
1919
pandas

tests/test_azure_specific.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,3 +206,13 @@ def test_adls_gen2_rename(azure_gen2_rig):
206206
p2 = p.rename(azure_gen2_rig.create_cloud_path("dir2"))
207207
assert not p.exists()
208208
assert p2.exists()
209+
210+
211+
def test_batched_rmtree_no_hns(azure_rig):
212+
p = azure_rig.create_cloud_path("new_dir")
213+
214+
p.mkdir()
215+
for i in range(400):
216+
(p / f"{i}.txt").write_text("content")
217+
p.rmtree()
218+
assert not p.exists()

0 commit comments

Comments
 (0)