Skip to content

fix(storage): raise a clear error in FsspecStore.from_url when the local directory does not exist - #4683

Open
1915rising wants to merge 2 commits into
zarr-developers:mainfrom
1915rising:fix/2808-fsspec-from-url-auto-mkdir
Open

1915rising wants to merge 2 commits into
zarr-developers:mainfrom
1915rising:fix/2808-fsspec-from-url-auto-mkdir

Conversation

@1915rising

@1915rising 1915rising commented Dec 1, 2026 •

Copy link
Copy Markdown

Summary

Fixes #2808. FsspecStore.from_url("file://.../new.zarr") failed on the first write with FileNotFoundError: .../new.zarr/zarr.json. The local filesystem is synchronous, so it gets wrapped, and it does not create directories on write unless auto_mkdir is set. A plain local path works because LocalStore creates parent directories itself.

Reworked following the feedback in this thread: instead of defaulting auto_mkdir to True, from_url now raises a clear FileNotFoundError at creation time when a local URL (scheme missing, file, or local) points at a directory that does not exist and the caller has not enabled auto_mkdir. The message names the missing directory and directs the caller to create it first or pass storage_options={'auto_mkdir': True}. Nothing is created silently. Read-only stores are exempt, since they never write. Filesystems the caller builds themselves are untouched, so an explicit auto_mkdir=False filesystem passed as a mapper still behaves as before, which an existing test covers.

Tests: tests/test_store/test_fsspec.py was 101 passed, 17 skipped on unmodified main and is 102 passed, 17 skipped with this change. The regression test now asserts the creation-time error and its message, that the same path works with auto_mkdir set, and that a read-only store at a missing path does not raise. It fails on unmodified code. This PR was prepared with AI assistance; I reviewed and tested every line.

Author attestation

  • I am a human, these are my changes, and I have reviewed and understood every change and can explain why each is correct.

TODO

  • Add unit tests and/or doctests in docstrings
  • Add docstrings and API docs for any new/modified user-facing classes and functions
  • New/modified features documented in docs/user-guide/*.md
  • Changes documented as a new file in changes/
  • GitHub Actions have all passed
  • Test coverage is 100% (Codecov passes)

@d-v-b

d-v-b commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

i don't think we want to make automatic directory creation the default.

@1915rising

Copy link
Copy Markdown
Author

Fair point. Silently creating directories can mask a mistyped path, and the default should not do that.

The bug in #2808 is that the failure surfaces as a FileNotFoundError on the first write, far from the actual cause. Would you prefer from_url to raise a clear error at creation time when the local directory does not exist? I can rework this PR to do that instead.

@d-v-b

d-v-b commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

yes, I think a clearer error message that directs people to change the relevant fsspec options would be a great addition

@1915rising 1915rising changed the title fix(storage): default auto_mkdir for local URLs in FsspecStore.from_url fix(storage): raise a clear error in FsspecStore.from_url when the local directory does not exist Dec 4, 2026
@1915rising

Copy link
Copy Markdown
Author

Reworked along the lines you suggested. from_url no longer defaults auto_mkdir; for a local URL whose directory does not exist, it now raises a FileNotFoundError at creation that names the directory and points to the auto_mkdir storage option. Tests updated: 102 passed, 17 skipped in tests/test_store/test_fsspec.py.

This branch has not been deployed

No deployments
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.

FileNotFoundError when using FsspecStore.from_url with a sync filesystem

2 participants