Skip to content

Commit 58aa954

Browse files
Raise when WebHDFS delete reports failure (#2502)
Co-authored-by: Martin Durant <martindurant@users.noreply.github.com>
1 parent 06f0a25 commit 58aa954

3 files changed

Lines changed: 28 additions & 1 deletion

File tree

‎docs/source/changelog.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Enhancements
2020

2121
Fixes
2222

23+
- Raise an error when WebHDFS refuses a delete instead of reporting success.
2324
- Keep failed whole-file cache refreshes eligible for retry instead of marking
2425
stale contents as current.
2526

‎fsspec/implementations/tests/test_webhdfs.py‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,30 @@ def test_rename_response_checked(monkeypatch):
331331
fs.mv("/source", "/target")
332332

333333

334+
def test_delete_response_checked(monkeypatch):
335+
"""WebHDFS must not report success when HDFS refuses a delete."""
336+
from unittest.mock import Mock
337+
338+
fs = object.__new__(WebHDFS)
339+
response = Mock()
340+
response.json.return_value = {"boolean": False}
341+
call = Mock(return_value=response)
342+
monkeypatch.setattr(fs, "_call", call)
343+
344+
with pytest.raises(FileNotFoundError, match="failed to delete"):
345+
fs.rm("/missing")
346+
call.assert_called_once_with(
347+
"DELETE", method="delete", path="/missing", recursive="false"
348+
)
349+
350+
with pytest.raises(FileNotFoundError, match="failed to delete"):
351+
fs.rm_file("/missing")
352+
353+
response.json.return_value = {"boolean": True}
354+
fs.rm("/dir", recursive=True)
355+
assert call.call_args.kwargs["recursive"] == "true"
356+
357+
334358
def test_ls_file_keeps_its_name(monkeypatch):
335359
"""LISTSTATUS on a file lists the file itself with an empty pathSuffix."""
336360
from unittest.mock import Mock

‎fsspec/implementations/webhdfs.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,12 +399,14 @@ def mv(self, path1, path2, **kwargs):
399399
raise OSError(f"WebHDFS failed to rename {path1!r} to {path2!r}")
400400

401401
def rm(self, path, recursive=False, **kwargs):
402-
self._call(
402+
response = self._call(
403403
"DELETE",
404404
method="delete",
405405
path=path,
406406
recursive="true" if recursive else "false",
407407
)
408+
if response.json()["boolean"] is not True:
409+
raise FileNotFoundError(f"WebHDFS failed to delete {path!r}")
408410

409411
def rm_file(self, path, **kwargs):
410412
self.rm(path)

0 commit comments

Comments
 (0)