Skip to content

fix(stores): <filepath@> insert checks stores.filepath_default; folder downloads work on older fsspec - #1731

Open
dimitri-yatsenko wants to merge 2 commits into
masterfrom
fix/store-follow-ups
Open

dimitri-yatsenko wants to merge 2 commits into
masterfrom
fix/store-follow-ups

Conversation

@dimitri-yatsenko

@dimitri-yatsenko dimitri-yatsenko commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

Summary

Follow-ups to the file-store and attachment changes in 2.3.6 (GHSA-94rh-cpp4-v56c). The path checks from that release are unchanged. Every change here refuses, or falls back to the safer path, when in doubt.

  • <filepath@> insert checks the right store. With no store named, <filepath@> records stores.filepath_default. The path check and the existence check used the backend of stores.default. When the two named different stores, an insert checked one store and recorded the other. Now the store name is resolved once, and every check uses that store.
  • Folder downloads on fsspec older than 2023.9. On those versions, fs.get(list, list) still expands the sources as glob patterns. A key containing [, * or ? could be paired with another key's local name. DataJoint now fetches the files one by one on those versions. A key ending in / (a directory marker) becomes a folder, not a file.
  • Empty folder objects on fsspec older than 2024.3.1. There, find(withdirs=True) does not list the folder itself, so the download raised FileNotFoundError. It now creates the empty folder. A folder that does not exist still raises.
  • The <attach> reuse check cannot block. _has_contents opens the file with O_NONBLOCK. If the open fails, the file counts as different, and the fetch moves on to the next free name.

Fixes #1713.

Changes

  • src/datajoint/builtin_codecs/filepath.py: resolve the store with use_filepath_default=True once, and use it for the spec, the backend, the error message and the recorded row.
  • src/datajoint/objectref.py: fetch files one by one unless fsspec is 2023.9.0 or later (an unrecognized version counts as old); treat keys ending in / as folders; create an empty folder that find does not list.
  • src/datajoint/builtin_codecs/attach.py: open with O_NONBLOCK; a failed open returns False.
  • tests/unit/conftest.py: a fresh_datajoint_import fixture. Some unit tests remove datajoint from sys.modules to import it afresh. They now put the original modules back afterwards. Before, later tests mixed two copies of the package, so a setting changed through one dj.config did not reach code reading the other. That is why tests/unit and tests/integration/test_path_confinement.py failed when run in one session.

Tests

  • Unit (tests/unit/test_path_confinement.py):
    • <filepath@> with stores.default and stores.filepath_default set to different stores: the file is found in, confined to, and recorded with the filepath store.
    • A store whose location is a symbolic link. A relative location, resolved against the working directory at call time.
    • Folder downloads with keys containing [, * and ? (only [ on Windows, where file names cannot contain the others), on the installed fsspec and with an older fsspec version reported. Also a directory-marker key, an empty folder that find does not list, and a missing folder.
    • A named pipe swapped in after the lstat check: the check returns False without blocking.
  • Integration (tests/integration/test_store_follow_ups.py):
    • <filepath@> insert and fetch with the two defaults set to different stores, on MySQL and PostgreSQL.
    • A folder object downloaded from the S3 test store, including keys with glob characters.
  • Before the change, 8 of the new unit tests fail with a current fsspec (2026.3.0): the two <filepath@> tests, the old-fsspec download test for each of its three reported versions, the directory-marker and empty-folder tests, and the named-pipe test. test_download_folder_keys_with_glob_characters passes on master with a current fsspec, because fsspec 2023.9 and later no longer expands the sources as patterns; the old-fsspec tests cover the case that failed. The symbolic-link, relative-location and missing-folder tests pass before and after. The <filepath@> integration tests fail before the change on both backends.
  • tests/unit together with tests/integration/test_path_confinement.py and tests/integration/test_schema.py now passes in one session; it failed before.
  • The full suite passes locally.
…wnloads on old fsspec

- <filepath@> with no store named resolves stores.filepath_default once,
  and runs the path and existence checks against that store, the one the
  row records. It used to build the backend from stores.default.
- ObjectRef.download() of a folder fetches files one by one on fsspec
  before 2023.9, where get(list, list) expands the sources as globs. A key
  ending in '/' becomes a folder. An empty folder that find() does not
  list (fsspec before 2024.3.1) is created instead of raising.
- The <attach> reuse check opens the file with O_NONBLOCK and treats a
  failed open as a different file, so a pipe swapped in after the lstat
  check cannot block the fetch.
- Tests: symbolic-link and relative store locations, an S3 folder
  download, and a fixture that restores the datajoint modules after the
  tests that import it afresh, so tests/unit and tests/integration can
  run in one session.

Fixes #1713.
Windows file names cannot contain them; the folder download tests keep
the '[' case there.

@MilagrosMarin MilagrosMarin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @dimitri-yatsenko, this is a careful set of follow-ups.

What I checked locally, with current master merged in:

  • Full suite on MySQL and PostgreSQL: 2071 passed, 17 skipped.
  • With master's source restored, 8 of the new unit tests fail on current fsspec, as described. The 4 <filepath@> integration tests fail on both backends.
  • With fsspec 2023.1.0 actually installed (not just the version reported), the new unit tests all pass. With master's source, 9 fail, including test_download_folder_keys_with_glob_characters, so that test does guard the real old-fsspec case.

Two small wording notes from probing fsspec 2023.1.0 through 2024.3.1 on the local and memory filesystems:

  • On 2023.1.0 and 2023.6.0, fs.get(list, list) with keys such as a[12].txt or b*.txt raised AssertionError (the two lists ended up different lengths). I could not get it to pair a key with another key's local name. The practical symptom seems to be "folder download fails" rather than silent mispairing. The fix is right either way, so this only affects the PR description.
  • The empty-folder comment says fsspec before 2024.3.1 leaves the folder out of find(withdirs=True). For local and memory I saw the change at 2023.9.0 (2024.2.0 already lists it). 2024.3.1 may be the right number for s3fs, which I did not test. If not, the comment could say 2023.9.0 or drop the version.

Resolving the store once and recording that same name makes <filepath@> much easier to reason about when the two defaults differ.

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

2 participants