Skip to content

Type put destinations and document path addressing (GH-1404) - #1426

Open
laughingman7743 wants to merge 6 commits into
masterfrom
fix/1404-typed-put-destinations
Open

laughingman7743 wants to merge 6 commits into
masterfrom
fix/1404-typed-put-destinations

Conversation

@laughingman7743

@laughingman7743 laughingman7743 commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

WHAT

put() now writes a local file to the key named after the file as it is, on both filesystems. This includes a file whose name ends in what looks like a version ID query. The docs now describe how keys that look like version paths, and bucket//, are addressed.

Behavior before this change (89ffcd9)

The examples use a local file named x?versionId=v1:

  • put(<file>, "s3://bucket/up/") built the destination bucket/up/x?versionId=v1, which was parsed as version v1 of up/x.
  • The upload then raised ValueError: Cannot write to the file with the version specified.
  • The same happened for a recursive put of its directory, for mode="create", and for the async _put().

Changes

  • Destinations. _put_pairs() returns an S3Path for each destination named after a local file. It is the parsed destination root with the rest of the local name added to its key as it is, through the new S3Path.with_key_suffix().
    • with_key_suffix() raises ValueError for a root that names a version. put() raises its own message before anything is uploaded: Cannot write to the file with the version specified.
    • S3PathPairing.s3_copy_pairs() (Act on listed identities in pairing and copy/mv/get (GH-1403) #1421) uses the same method, and keeps its message Cannot copy to a versioned file.
    • A destination that is the root itself, or one item of a list of destinations, stays the caller's string, with string semantics.
  • Writes. put_file() and the async _put_file() accept an S3Path, also in a transaction of either filesystem.
    • The new _open_path() opens an S3Path with the transaction handling of open(), and get_file() reads through it too.
    • The transaction opener of the async filesystem also accepts an S3Path.
  • File methods. url(), metadata(), getxattr() and setxattr() of a file now address its bucket, key and version. The filesystems' sign(), metadata(), getxattr() and setxattr() accept an S3Path.
  • Callback labels. The branches of the callback of get() and put() are named after their paths as strings, on both filesystems. The async _get() and _put() run their transfers through one loop, _transfer_pairs(), which works as fsspec's loop for lists of paths and labels each branch with the string of its path. It replaces the _get_pairs() that Act on listed identities in pairing and copy/mv/get (GH-1403) #1421 added. The async callbacks stay unlocked, as before.
  • Docs. A new "Path addressing" section in docs/filesystem.md covers decisions 7, 8 and 10 of the Settle the response models, S3Object, and the listing cache #1341 audit:
    • A key that ends in a version ID query cannot be named by a path string, and there is no escape syntax. An S3Path names it, and the section lists the methods that accept one.
    • The listings and the operations built on them act on such keys. The compositions that pass path strings back do not keep this identity: fsspec.open(), open_files(), get_mapper().
    • S3Path(bucket, "") is the bucket.
    • A file opened with an S3Path of such a key has the key's name as its path string. Its methods address the key, but a pickled copy reopens the path string.
    • s3://bucket// names the key / for cat_file(), rm_file() and a non-recursive chmod(), and the bucket for info() and the listings. A recursive chmod() changes the ACLs of the listed objects, including /, and not that of the bucket. A write raises ValueError. Each of these was reproduced against the fake store at this commit.

This is step 4 of 4 of #1381 (plan in this comment), and completes it. Two older costs found in the review are filed as #1427: the duplicated upload body, and the source checks and part windowing of the async put().

WHY

Closes #1404.

TEST

Tested commit: e9bc32d.

  • These pass:
    • just lint and just docs lint;
    • a Sphinx build of the working tree, whose only warnings are the duplicate object descriptions that the other pages already have;
    • just benchmark test (363 passed, 1 skipped).
  • New tests against the offline fake S3 store:
    • test_put_names_destinations_after_local_files, sync and async, cases file, dir and create. They compare the stored keys, the PutObject and HeadObject keys, IfNoneMatch, and the callback's destination labels.
    • test_put_in_transaction_names_destinations_after_local_files, sync and async: nothing is written before the transaction ends, and the key afterwards.
    • TestS3Path::test_with_key_suffix and test_with_key_suffix_of_version.
    • TestS3File::test_append_to_path_as_it_is: append mode of an S3Path, which Act on listed identities in pairing and copy/mv/get (GH-1403) #1421 made possible but no test exercised (carried over from Act on listed identities in pairing and copy/mv/get (GH-1403) #1421).
    • TestS3File::test_path_methods_address_path_as_it_is: url(), metadata(), getxattr() and setxattr() of a file opened with an S3Path. All four fail with the source at 522d2ca.
  • Of the 17 new tests, 16 fail with the source at 89ffcd9. The append test passes there, as noted above.
  • Mutations, each of which fails the tests that protect it:
    • not passing an S3Path path to the callback as a string: the sync put() destination, the async _put() destination and the async _get() source (3, 3 and 1 tests);
    • not joining a written S3Path file to the transaction (the sync transaction test).
  • The full tests/pyathena/filesystem/ suite against AWS, run locally in parts with a per-test timeout:
    • the files other than test_s3.py, including the fsspec conformance tests: 1043 passed, 3 skipped;
    • TestS3FileSystem: 715 passed, 3 skipped;
    • TestS3File and TestCompressedBuffer: 103 passed.

🤖 Generated with Claude Code

)
)

async def _transfer_pairs(

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Self-review round one (implementation behavior): FINDINGS, repaired in e9bc32d

Scope: the full diff 89ffcd97..522d2cab.

Passes:

  • /code-review at high effort.
  • /simplify, with four cleanup agents: reuse (CLEAN), simplification, efficiency (CLEAN) and altitude.

Findings and repairs:

  1. The async _get()/_put() took a threading.Lock on the event loop (/code-review). The wrapped callback took it on the loop thread while worker threads held it for their child callbacks. That stalls the loop, and deadlocks it if a child callback calls a sync method of the filesystem, which waits on the loop.
  2. The path methods of a file opened with an S3Path used its path string (altitude).
    • For S3Path("bucket", "a/x?versionId=null"), url(), metadata() and getxattr() signed and read the null version of a/x, and setxattr() rejected the file as a version.
    • The docs listed this as a limit, and named sign(), which S3File does not have (its method is url()).
    • Repair: the filesystems' sign(), metadata(), getxattr() and setxattr() accept an S3Path, and S3File passes its bucket, key and version (_s3_path). The docs now name only pickling as the limit.
    • Test: TestS3File::test_path_methods_address_path_as_it_is; all four cases fail at 522d2ca.
  3. The versioned-root errors changed (/code-review, altitude). copy() of listed sources and put() raised with_key_suffix()'s generic message.
    • Repair: s3_copy_pairs() raises Cannot copy to a versioned file. again, and _put_pairs() raises Cannot write to the file with the version specified., the message that the string path gave at open(). The Raises of put() and _put() say so.
  4. Cleanups (simplification):
    • _put_pairs() returns early when no destination is named after a local file.
    • put_file() and the async transaction write parse their destination once.
    • The latter invalidates through self._invalidate().
  5. Tests (/code-review):
    • The append test of a typed path moved to TestS3File.
    • The sync put test compares the callback's labels exactly (dir includes the directory's bucket/up).

Deferred, with reasons:

Validation:

  • just lint, just docs lint and just benchmark test pass.
  • The filesystem suite against AWS, in parts: 1043 + 715 + 103 passed, 6 skipped.

"""
return self.with_version_id(None) if self.version_id == "null" else self

def with_key_suffix(self, suffix: str) -> S3Path:

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Self-review round two (claims, callers, AWS operator, evidence): CLEAN

Scope:

Claims checked:

  1. The before-state. At 89ffcd9, put of the file x?versionId=v1 raises ValueError: Cannot write to the file with the version specified. This holds for a single file, a recursive directory and mode="create", sync and async, reproduced against the fake store.
  2. "A destination that is the root itself, or one item of a list, stays the caller's string." _put_pairs() returns the pairs unchanged when rpath is a list or every destination equals it. Otherwise only the destinations other than rpath are typed.
    • So put(file, "s3://bucket/up/x?versionId=v1") still names that version and fails at open(), as documented.
  3. "The async callbacks stay unlocked, as before." At 89ffcd9:
    • the async _get() ran Act on listed identities in pairing and copy/mv/get (GH-1403) #1421's _get_pairs(), without a lock;
    • the async _put() passed the callback to fsspec's _put(), without a lock.
      _transfer_pairs() keeps both, and calls set_size, branched(..., **kwargs), the transfer and _run_coros_in_chunks(..., callback=) as fsspec 2026.9.0 does. The local directories are created as fsspec's _get() creates them, and _put() filters the directories out before the transfers, as before.
  4. The widened path methods behave the same for strings:
    • sign(), metadata() and getxattr() parse a string as before.
    • setxattr() now passes its parsed path to metadata() and invalidates it with _invalidate(). Its path never has a version (it raises first), and the name walk evicts at least what invalidate_cache() did.
    • The async sign, metadata, getxattr and setxattr hand the path to the sync methods unchanged.
  5. S3File now always passes S3Path(bucket, key, version_id) to these methods. For a file opened by a string, that is the parse of its path, including the pinned ?versionId= of version_aware, so the requests are the same. No test patches these methods.
  6. The bucket// section matches the probe at this commit:
    • info → HeadBucket;
    • cat_file/rm_file/chmod → the key /;
    • ls/find → the bucket listing;
    • a recursive chmod → PutObjectAcl of / and a, without PutBucketAcl;
    • pipe_file → ValueError.
  7. The other docs statements were checked against the code:
    • the list of methods that accept an S3Path, including S3File;
    • the compositions through strings (fsspec.open(), open_files(), get_mapper());
    • the pickling limit: fsspec's __reduce__ reopens self.path.

Existing callers:

  • No public signature was narrowed. put_file, sign, metadata, getxattr and setxattr (and the async ones) only accept more. S3Path.with_key_suffix() is new.
  • Error messages for strings are unchanged.
  • The new raise for a versioned put() root replaces the same message, which each file raised at open(). It now comes before any upload.

AWS operator:

  • put() sends the same requests to the literal keys.
  • mode="create" sends HeadObject and a conditional PutObject as before.
  • The file methods address the key instead of a version.
  • No new permission.

Evidence:

  • Local runs, in the round-one record.
  • The 16 new tests that fail at 89ffcd9, and the four file-method tests that fail at 522d2ca.
  • CI against AWS has not run yet (Draft).

"""
return self.with_version_id(None) if self.version_id == "null" else self

def with_key_suffix(self, suffix: str) -> S3Path:

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Independent review (relayed result, Codex): CLEAN

Reviewer and run:

Coverage, in the reviewer's words:

  • "put()/_put() pairing against fsspec 2026.9.0: globs, recursion, maxdepth, lists, trailing slashes, bucket roots and versioned roots."
  • "Typed upload destinations, create mode and both filesystems' transactions."
  • "Async batching, callback labels and contexts, return values, and _S3BatchTasks cancellation cleanup."
  • "File and filesystem URL/metadata methods, including setxattr() lookups and cache invalidation."
  • "Path-addressing documentation, new regression assertions and existing compatibility coverage."

Result: "CLEAN — No actionable findings."

The independent review is complete. The PR moves to Ready for CI.

@laughingman7743
laughingman7743 marked this pull request as ready for review November 17, 2026 15:28
@laughingman7743
laughingman7743 force-pushed the fix/1404-typed-put-destinations branch from e9bc32d to d1789ce Compare November 21, 2026 12:48
)
)

async def _transfer_pairs(

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Rebase onto #1398, and independent review of the resolution (relayed result, Codex): FINDINGS (4), repaired in 0ee4e26

Rebase:

Reviewer and run:

Coverage, in the reviewer's words: the duplicate check "still runs before transfers start", explicit destinations "compare as protocol-stripped strings", generated children "compare by S3Path fields, and the only string that can appear alongside them is their distinct root", and async outfile downloads "still run one at a time in pair order".

Findings and repairs:

  1. Medium: a directory-only upload below a versioned root raised. For example, put(["a/empty", "b/empty"], "s3://bucket/key?versionId=v1", recursive=True) named destinations for the directories and raised, though it uploads nothing. The same put() of empty directories was deferred in round one as intended; this finding reverses that.
    • Repair: only a local file named below the root gets a typed destination, and only then is the root's version checked. A directory keeps its string destination, which put_file() skips.
    • Test: test_put_below_versioned_root[False] fails at d1789ce. [True] keeps the raise for a file.
  2. Medium: the async transfers bypassed Callback.branch_coro(). fsspec's _put() ran each upload through callback.branch_coro(self._put_file). _transfer_pairs() called branched() directly, so a callback that overrides branch_coro() lost its records.
    • Repair: _transfer_pairs() runs each transfer through callback.branch_coro(). The coroutine it wraps receives the string labels and transfers the paths as they are.
    • Test: test_transfers_run_through_branch_coro (async _get and _put) fails at d1789ce.
  3. Low: the Raises of put()/_put() described the version error too narrowly. A local file put directly to a version path also raises, at open(). Repair: they now say "a destination names a version, also when rpath names one and a local file is named below it".
  4. Low: _put_pairs() said a destination in a list is the caller's string. In fact the protocol is stripped. Repair: "a string without the protocol".

Validation at 0ee4e26:

  • just lint and just benchmark test pass.
  • The filesystem suite against AWS, in parts: 1050 + 720 + 103 passed, 6 skipped.

An independent follow-up of these repairs follows.

)
)

async def _transfer_pairs(

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Independent follow-up of the rebase repairs (relayed result, Codex): FINDINGS (4). 2 were repaired in 798b7d3; 2 predate #1426 and are added to #1427

Reviewer and run:

  • Reviewer: Codex CLI codex exec, model gpt-6.2-astra, reasoning effort max, read-only. Session 01a1fe39-a600-7620-8194-a6c1db3ed553.
  • Scope: a detached snapshot of 0ee4e26, reviewing d1789cee..0ee4e262.
  • This was a static review.

Coverage, in the reviewer's words: upload pairing "preserves literal suffixes for files named below the root, keeps directory destinations as strings, and checks duplicate file destinations before scheduling uploads", plus the callback arguments, batching, return values, cancellation, the two new tests and the docstrings.

Findings:

  1. High: an upload could start after cancellation. If a branch_coro() wrapper awaited before invoking the transfer, the transfer's task had not yet joined _S3BatchTasks. A cancelled _put() then raised CancelledError to the caller, and the wrapper uploaded the file once released; _get() likewise wrote the local file.
    • Repair: each transfer's coroutine adds its task to the batch (_S3BatchTasks.track()) before it awaits the wrapper.
    • Test: test_cancelled_put_starts_no_waiting_transfer fails at 0ee4e26 (the file is uploaded after the cancellation).
  2. Medium: _get() returns None, where fsspec returns the list of the transfer results. This predates Type put destinations and document path addressing (GH-1404) #1426; the async _get() has returned None since before Act on listed identities in pairing and copy/mv/get (GH-1403) #1421. It is added to Share the upload body of put_file() with the async transaction write, and check put sources once #1427 (comment).
  3. Low: a skipped _put() of a single directory calls set_size(0) and returns [], where fsspec returns None. This also predates Type put destinations and document path addressing (GH-1404) #1426; added to Share the upload body of put_file() with the async transaction write, and check put sources once #1427.
  4. Low: the Raises of put()/_put() overstated the version check. A list destination with a version is accepted when its source is a directory, which uploads nothing.
    • Repair: they now say "the destination of a local file names a version".

Validation at 798b7d3:

  • just lint passes.
  • The filesystem tests other than test_s3.py: 1051 passed, 3 skipped. They include test_s3_async.py and the fsspec conformance tests, against AWS.
  • test_s3.py is unaffected (only a docstring changed in s3.py) and passed at 0ee4e26: 720 + 103 passed, 3 skipped.
  • CI at 0ee4e26 passed.

An independent follow-up of this repair follows.

laughingman7743 and others added 6 commits November 21, 2026 22:30
put() and the async _put() named the destination of a local file by
joining its name to the destination string, which was parsed again: a
file named x?versionId=v1 was taken for version v1 of the key x, and
the upload raised that a version cannot be written.

- _put_pairs() returns an S3Path for a destination named after a local
  file: the destination root parsed, with the rest of the local name
  added to its key as it is (S3Path.with_key_suffix(), which
  s3_copy_pairs() of the pairing uses as well). A destination that is
  the root itself, or one of a list, stays the caller's string.
- put_file() and the async _put_file(), also in a transaction, write an
  S3Path by its bucket and key; _open_path() opens it with open()'s
  transaction handling, and get_file() reads through it.
- _S3LockedCallback names the branches of S3Path sources and
  destinations by their strings, so that the async _get() and _put()
  run fsspec's own loops for lists of paths again; _get_pairs() is
  removed.
- docs/filesystem.md documents the addressing of keys that look like
  version paths (the S3Path methods, the string compositions, and the
  path string of a file opened with an S3Path) and of bucket//.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review repairs:

- url(), metadata(), getxattr() and setxattr() of a file address its
  bucket, key and version: sign(), metadata(), getxattr() and
  setxattr() of the filesystems accept an S3Path. A file opened with
  the S3Path of a key such as a/x?versionId=null signed and looked up
  the null version of a/x. Only a pickled copy still reopens the path
  string, which the docs say.
- The async _get() and _put() name the branches of their callback
  after their paths as strings in a transfer loop of their own, as
  fsspec runs them, instead of taking the lock of _S3LockedCallback on
  the event loop, which a callback that calls the filesystem could
  deadlock.
- copy() and put() to a destination root that names a version raise
  their own messages again, and put() and _put() say so.
- _put_pairs() returns early when no destination is named after a
  local file, put_file() parses its destination once, and the async
  transaction write invalidates through the filesystem.
- The append test of a typed path moves to TestS3File, and the sync put
  test compares the labels of the callback exactly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The destinations that put() names after local files are S3Path objects,
so the test of #1398 that sorts them compares their strings.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…H-1404)

Independent review of the rebase onto #1398:

- put() and _put() raise for a root that names a version only when a
  local file is named below it; local directories, which upload
  nothing, keep their string destinations, so a tree of empty
  directories uploads nothing again instead of raising.
- The transfers of the async _get() and _put() run through the
  callback's branch_coro(), as fsspec runs them, so that a callback
  that overrides it sees each transfer, with the paths still named as
  strings.
- The docstrings of put(), _put() and _put_pairs() state which
  destinations are typed and when a version raises.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…1404)

Independent review follow-up: a callback whose branch_coro() wrapper
waited before starting a transfer left the transfer outside the batch,
so a cancelled _put() or _get() could still upload or write the file
afterwards. Each transfer now adds its task to the batch before the
wrapper runs. The Raises of put() and _put() say that only the
destination of a local file is checked for a version.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Independent review follow-up: _transfer_pairs() asked the callback's
branch_coro() for the wrapper of a transfer only when the transfer
started, so a callback that waits in its wrappers until every transfer
is wrapped hung with batch_size=1. The wrappers are now created with
the coroutines, before any transfer is scheduled, and the task still
joins the batch before its wrapper runs. The cancellation test checks
that the waiting wrapper was cancelled before _put() raised.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@laughingman7743
laughingman7743 force-pushed the fix/1404-typed-put-destinations branch from 798b7d3 to 7eb9cd6 Compare November 21, 2026 13:44
)
)

async def _transfer_pairs(

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Rebase onto #1423, and independent follow-up of the cancellation repair (relayed result, Codex): FINDINGS (3). 2 were repaired in 7eb9cd6; 1 is accepted within the interrupt guarantee

Rebase:

Reviewer and run:

  • Reviewer: Codex CLI codex exec, model gpt-6.2-astra, reasoning effort max, read-only. Session 01a1fe47-6d6c-7531-b9de-7f50a540855b.
  • Scope: a detached snapshot of 798b7d3, reviewing 0ee4e262..798b7d3e.
  • This was a static review.
  • Covered, in the reviewer's words: "both _put() and _get() now cancel and wait for the wrapper before propagating cancellation. fsspec still enforces batch_size, leaves unscheduled pairs idle, and preserves _put() result order."

Findings:

  1. Medium: deferring branch_coro() could deadlock a callback. fsspec creates every wrapper before any transfer runs. With batch_size=1, a callback that waits in its wrappers until both are created hung on the first file.
    • Repair: _transfer_pairs() asks branch_coro() for each wrapper when it creates the coroutines, before any is scheduled. The task still joins the batch before its wrapper runs.
    • Test: test_transfers_are_wrapped_before_they_run fails at 798b7d3.
  2. Low: the cancellation test could pass with an upload pending. It slept 100 ms after releasing the wrapper.
    • Repair: the wrapper records its cancellation, and the test asserts it right after _put() raises, before anything is released.
  3. Medium (accepted): batch cancellation can interrupt a transfer's cleanup when a wrapper runs the transfer in a task of its own. If that child task already received a per-file cancellation, the batch's cancellation of the tracked wrapper is a second cancellation, which can stop S3Executor.run()'s wait for the running request.
    • This requires a callback whose branch_coro() wrapper creates its own task. It is a repeated interrupt of one operation, which the filesystem's interrupt guarantee covers only to the extent of no permanent hang.
    • The simple wrapper case (a wrapper that awaits before starting the transfer) is the one that Type put destinations and document path addressing (GH-1404) #1426 fixes, and keeping its task out of the batch would bring back the upload after cancellation. No change.

Validation at 7eb9cd6, rebased on 703aaad:

  • just lint and just benchmark test pass.
  • The filesystem suite against AWS, in parts: 1052 + 721 + 103 passed, 6 skipped.
  • CI at 798b7d3 (before the rebase) passed.

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.

Type generated put destinations and document path addressing limits (#1381 step 4)

1 participant