Skip to content

Raise when WebHDFS delete reports failure - #2502

Merged
martindurant merged 2 commits into
fsspec:masterfrom
shashank11yadav:fix/webhdfs-rm-boolean
Dec 1, 2026
Merged

martindurant merged 2 commits into
fsspec:masterfrom
shashank11yadav:fix/webhdfs-rm-boolean

Conversation

@shashank11yadav

@shashank11yadav shashank11yadav commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #2501

WebHDFS answers DELETE with {"boolean": true|false}, but WebHDFS.rm never read that field. When HDFS refused a delete, for example because the path is missing, rm and rm_file returned as if the delete had worked.

This change makes rm check the field the way mv already checks RENAME. When the result is not true, rm raises FileNotFoundError. rm_file and WebHDFile.discard get the check through rm. cp_file's cleanup already suppresses FileNotFoundError, so it is unchanged.

Behaviour change: rm and rm_file on a missing path used to pass silently and now raise FileNotFoundError. This matches the local and memory filesystems.

Why FileNotFoundError and not plain OSError as mv uses: it matches fsspec's convention for rm on a missing path, and it lets cp_file's cleanup suppress a failed temporary delete without hiding the original copy error. If you prefer OSError, 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 the htcluster fixture, so they were not run.
  • The new test test_delete_response_checked fails without the fix and passes with it.
  • ruff check fsspec passes. ruff format --check fsspec passes. codespell exits 0. ruff 0.14.3 and codespell 2.4.0 were used.
  • pre-commit run --all-files was not run. It downloads hook environments from GitHub, which the test environment cannot reach.
  • Not tested against a real HDFS cluster. The fix assumes HDFS returns false for a missing path, per Hadoop's FileSystem.delete semantics.

@JonnyFaeth

Copy link
Copy Markdown

I checked the cp_file cleanup rationale at dcbb33c with the real cp_file → rm path and a mocked transport. Both DELETE responses (true and false) preserve the exact original rename exception. Changing the new exception to plain OSError, as discussed in the description, makes the false-response case fail because cleanup replaces the original error. So that alternative would need a corresponding cleanup decision, not just a one-word swap.

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.

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.
@martindurant
martindurant merged commit 58aa954 into fsspec:master Dec 1, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WebHDFS.rm ignores the boolean result of the DELETE call

3 participants