Skip to content

Accept a list of paths in WebHDFS.rm - #2560

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

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

Conversation

@shashank11yadav

@shashank11yadav shashank11yadav commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #2559

WebHDFS.rm overrides the base rm and passed its argument straight to _call, so calling it with a list of paths raised TypeError before any request was sent. The base API documents path as "str or list of str".

WebHDFS.rm now handles a list by calling itself once per path, the same way ArrowFSWrapper.rm does. Before the loop it removes duplicate paths (after stripping the protocol and any trailing slash) and sorts the rest deepest first, so a listed child is deleted before its parent. Without this, a duplicate, or a child listed after its parent was removed recursively, was requested again after it was gone, and #2502's missing-path check raised and stopped the rest of the list. A path that is really missing still raises. Each element is a string, so the recursion stops after one level and does not go through rm_file. Single-path calls are unchanged. The changelog has a new entry under Dev > Fixes.

Tested:

  • The WebHDFS test module, run with uv run --no-sync python -m pytest fsspec/implementations/tests/test_webhdfs.py -v, passes.
  • The new tests test_rm_list_of_paths, test_rm_list_duplicate_paths and test_rm_list_parent_and_child pass. On master all three fail, because a list raises TypeError there. The last two use the two cases from the review.
  • The ruff lint check and the ruff format check, both on the fsspec package with ruff 0.14.3, pass.
  • pre-commit run --all-files was not run.

WebHDFS.rm passed its argument straight to the request, so a list of
paths raised TypeError before anything was sent. Delete each path in
turn, as ArrowFSWrapper.rm does.
@lexingtonhibiki

Copy link
Copy Markdown
Contributor

One interaction with #2502 now that it has merged: the list loop can raise on a path it already removed, before reaching the rest of the list.

I applied only the list hunk from 80195d7 to current master and ran the real WebHDFS.rm and HTTP client against a local stub that returns the WebHDFS DELETE boolean. With /d/file under /d and an unrelated /other, rm(["/d", "/d/file", "/other"], recursive=True) deletes /d, then raises FileNotFoundError on its child and never sends DELETE for /other. Child-first succeeds. An exact duplicate also stops the loop early: rm(["/other", "/other", "/last"]) leaves /last. Distinct paths and a genuinely missing scalar behaved as expected on the combined code. This was an HTTP fixture, not a live HDFS cluster.

Could we add a duplicate-path test and a recursive parent-plus-child test after rebasing? Deduplicating the list and handling children before listed parents would avoid creating these missing-path errors without weakening #2502's scalar check.

When rm gets a list, drop duplicate paths and delete children before
their listed parents. A path removed earlier in the list is no longer
reported as missing, so the remaining paths are still deleted.
@lexingtonhibiki

Copy link
Copy Markdown
Contributor

Thanks for adding the duplicate and parent-before-child regressions. I reran the original loopback HTTP fixture against the exact 95f9fb6 WebHDFS module, without mocking _call. Both original failures now pass: the duplicate sends a single DELETE and reaches the remaining path, and the recursive case deletes the child first and reaches the unrelated path. A protocol/trailing-slash alias also sends a single DELETE. Genuinely missing scalar and list paths still raise FileNotFoundError. All 12 fixture scenarios matched the revised behavior. This was a local WebHDFS HTTP stub, not a live HDFS cluster.

@martindurant
martindurant merged commit fb5f96c into fsspec:master Dec 3, 2026
8 of 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 raises TypeError when given a list of paths

3 participants