Skip to content

Create parent directories before FSMap batch writes - #2287

Merged
martindurant merged 3 commits into
fsspec:masterfrom
AryanRG:fix/fsmap-setitems-parent-retry
Oct 26, 2026
Merged

martindurant merged 3 commits into
fsspec:masterfrom
AryanRG:fix/fsmap-setitems-parent-retry

Conversation

@AryanRG

@AryanRG AryanRG commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

FSMap.setitems({"foo/bar": b"baz"}) fails on a local filesystem with auto_mkdir=False, while assigning the same key through __setitem__ works.

Create each distinct parent directory before the bulk write, matching __setitem__. This also lets deferred local transaction writes commit when their parent directories don't exist. The batch is written once, without retrying errors. Key/value conversion is unchanged, and an empty batch creates no directories.

Fixes #1041.

Tested the mapping regressions and the available full suite on macOS with Python 3.12. Ruff and the configured pre-commit hooks pass. Optional backend/service tests were skipped where dependencies were unavailable; the full cloud and platform matrix was not run locally.

Prepared with AI assistance.

@AryanRG
AryanRG force-pushed the fix/fsmap-setitems-parent-retry branch from 290077f to 61bd21c Compare October 14, 2026 15:51
@AryanRG
AryanRG marked this pull request as ready for review October 14, 2026 15:52
@AryanRG

AryanRG commented Oct 19, 2026

Copy link
Copy Markdown
Contributor Author

Resolved the merge conflict and kept both sets of mapping tests. The updated branch passes the available local suite.

Comment thread fsspec/mapping.py Outdated
Comment on lines +138 to +139
# Missing parent directories: create them, as __setitem__ does,
# then retry the bulk write once. Successful writes skip this.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, it unconditionally calls mkdirs first - so we can do that.

@AryanRG AryanRG Oct 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You’re right, that matches __setitem__. I’ll update it to create the parent directories before the batch write.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to create the parent directories before the batch write, matching __setitem__. Added transaction and error-handling tests too. Thanks!

@AryanRG AryanRG changed the title Retry FSMap batch writes after creating missing parent directories Create parent directories before FSMap batch writes Oct 23, 2026
@martindurant
martindurant merged commit 7aa0383 into fsspec:master Oct 26, 2026
11 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.

FSMap.setitems fails when FSMap.__setitem__ succeeds (nested directory on local filesystem).

2 participants