Repository navigation
Raise when WebHDFS delete reports failure - #2502
Conversation
|
I checked the Optional regression below. The file runs 7 passed, 16 skipped on Windows/Python 3.12; the 16 cluster tests remain untested. Ruff check/format pass. This is a mocked-transport cleanup contract test, not evidence about real HDFS failure responses, and is not claimed to fail on the parent (which ignored false). @pytest.mark.parametrize("deleted", [False, True])
def test_copy_cleanup_keeps_original_error(monkeypatch, deleted):
from io import BytesIO
from unittest.mock import Mock
fs = object.__new__(WebHDFS)
original = RuntimeError("rename failed")
monkeypatch.setattr(fs, "open", Mock(side_effect=[BytesIO(b"payload"), BytesIO()]))
monkeypatch.setattr(fs, "mv", Mock(side_effect=original))
response = Mock()
response.json.return_value = {"boolean": deleted}
call = Mock(return_value=response)
monkeypatch.setattr(fs, "_call", call)
with pytest.raises(RuntimeError) as error:
fs.cp_file("/source", "/target")
assert error.value is original
call.assert_called_once()
assert call.call_args.args == ("DELETE",)
assert call.call_args.kwargs["path"].startswith("/.tmp.")
assert call.call_args.kwargs["recursive"] == "false"AI disclosure: Codex authored and executed this test and review under Jonathan’s standing authorization; Jonathan has not personally reviewed this specific result. |
dcbb33c to
52e4163
Compare
WebHDFS answers DELETE with {"boolean": true|false}. rm ignored it, so
rm and rm_file returned as if the delete worked even when HDFS refused,
for example for a missing path. Check the field as mv already does for
RENAME and raise FileNotFoundError.
52e4163 to
ede1362
Compare
Fixes #2501
WebHDFS answers DELETE with
{"boolean": true|false}, butWebHDFS.rmnever read that field. When HDFS refused a delete, for example because the path is missing,rmandrm_filereturned as if the delete had worked.This change makes
rmcheck the field the waymvalready checks RENAME. When the result is nottrue,rmraisesFileNotFoundError.rm_fileandWebHDFile.discardget the check throughrm.cp_file's cleanup already suppressesFileNotFoundError, so it is unchanged.Behaviour change:
rmandrm_fileon a missing path used to pass silently and now raiseFileNotFoundError. This matches the local and memory filesystems.Why
FileNotFoundErrorand not plainOSErrorasmvuses: it matches fsspec's convention forrmon a missing path, and it letscp_file's cleanup suppress a failed temporary delete without hiding the original copy error. If you preferOSError, it is a one-word change.Changelog: one line added under Dev > Fixes.
How it was tested:
fsspec/implementations/tests/test_webhdfs.py: 5 passed, 16 skipped. The 16 skipped tests need thehtclusterfixture, so they were not run.test_delete_response_checkedfails without the fix and passes with it.ruff check fsspecpasses.ruff format --check fsspecpasses.codespellexits 0. ruff 0.14.3 and codespell 2.4.0 were used.pre-commit run --all-fileswas not run. It downloads hook environments from GitHub, which the test environment cannot reach.falsefor a missing path, per Hadoop'sFileSystem.deletesemantics.