Repository navigation
Type put destinations and document path addressing (GH-1404) - #1426
laughingman7743 wants to merge 6 commits into
Conversation
| ) | ||
| ) | ||
|
|
||
| async def _transfer_pairs( |
There was a problem hiding this comment.
Self-review round one (implementation behavior): FINDINGS, repaired in e9bc32d
Scope: the full diff 89ffcd97..522d2cab.
Passes:
/code-reviewat high effort./simplify, with four cleanup agents: reuse (CLEAN), simplification, efficiency (CLEAN) and altitude.
Findings and repairs:
- The async
_get()/_put()took athreading.Lockon 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.- Repair:
_S3LockedCallbackno longer converts labels. The syncget()andput()passstr()of their S3 path, as Act on listed identities in pairing and copy/mv/get (GH-1403) #1421 did. - The async
_get()/_put()run their transfers through_transfer_pairs(), which works as fsspec's loop for lists of paths and labels each branch with the string of its path, without a lock, as before Type put destinations and document path addressing (GH-1404) #1426. It replaces the_get_pairs()of Act on listed identities in pairing and copy/mv/get (GH-1403) #1421. - Mutations of each conversion fail the label tests (sync
put, async_put, async_get).
- Repair:
- The path methods of a file opened with an
S3Pathused its path string (altitude).- For
S3Path("bucket", "a/x?versionId=null"),url(),metadata()andgetxattr()signed and read thenullversion ofa/x, andsetxattr()rejected the file as a version. - The docs listed this as a limit, and named
sign(), whichS3Filedoes not have (its method isurl()). - Repair: the filesystems'
sign(),metadata(),getxattr()andsetxattr()accept anS3Path, andS3Filepasses 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.
- For
- The versioned-root errors changed (
/code-review, altitude).copy()of listed sources andput()raisedwith_key_suffix()'s generic message.- Repair:
s3_copy_pairs()raisesCannot copy to a versioned file.again, and_put_pairs()raisesCannot write to the file with the version specified., the message that the string path gave atopen(). TheRaisesofput()and_put()say so.
- Repair:
- 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().
- Tests (
/code-review):- The append test of a typed path moved to
TestS3File. - The sync
puttest compares the callback's labels exactly (dirincludes the directory'sbucket/up).
- The append test of a typed path moved to
Deferred, with reasons:
- The duplicated upload body of
put_file()and the async transaction write, and the async_put()source check and part windowing: these predate this PR, and are filed as Share the upload body of put_file() with the async transaction write, and check put sources once #1427. - Slicing
other_paths()destinations to derive the suffix. As in Act on listed identities in pairing and copy/mv/get (GH-1403) #1421,test_s3_copy_pairsand theputtests would fail if fsspec named destinations differently. - A
put()of only empty directories under a versioned root now raises. This is intended: such a root names an object. - The
stringify_pathguard repeated input_file/cp_file/get_file. Kept deliberately (Act on listed identities in pairing and copy/mv/get (GH-1403) #1421):stringify_pathwould convert anS3Pathif it ever gained__fspath__.
Validation:
just lint,just docs lintandjust benchmark testpass.- 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: |
There was a problem hiding this comment.
Self-review round two (claims, callers, AWS operator, evidence): CLEAN
Scope:
- the full diff
89ffcd97..e9bc32df7202230fbd41f84c03583a8a06e67d7b; - the PR body, the commit messages, the docstrings and the new "Path addressing" section;
- Share the upload body of put_file() with the async transaction write, and check put sources once #1427.
Claims checked:
- The before-state. At 89ffcd9,
putof the filex?versionId=v1raisesValueError: Cannot write to the file with the version specified.This holds for a single file, a recursive directory andmode="create", sync and async, reproduced against the fake store. - "A destination that is the root itself, or one item of a list, stays the caller's string."
_put_pairs()returns the pairs unchanged whenrpathis a list or every destination equals it. Otherwise only the destinations other thanrpathare typed.- So
put(file, "s3://bucket/up/x?versionId=v1")still names that version and fails atopen(), as documented.
- So
- "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 callsset_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.
- the async
- The widened path methods behave the same for strings:
sign(),metadata()andgetxattr()parse a string as before.setxattr()now passes its parsed path tometadata()and invalidates it with_invalidate(). Its path never has a version (it raises first), and the name walk evicts at least whatinvalidate_cache()did.- The async
sign,metadata,getxattrandsetxattrhand the path to the sync methods unchanged.
S3Filenow always passesS3Path(bucket, key, version_id)to these methods. For a file opened by a string, that is the parse of itspath, including the pinned?versionId=ofversion_aware, so the requests are the same. No test patches these methods.- 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/anda, without PutBucketAcl; pipe_file→ValueError.
- The other docs statements were checked against the code:
- the list of methods that accept an
S3Path, includingS3File; - the compositions through strings (
fsspec.open(),open_files(),get_mapper()); - the pickling limit: fsspec's
__reduce__reopensself.path.
- the list of methods that accept an
Existing callers:
- No public signature was narrowed.
put_file,sign,metadata,getxattrandsetxattr(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 atopen(). 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:
| """ | ||
| return self.with_version_id(None) if self.version_id == "null" else self | ||
|
|
||
| def with_key_suffix(self, suffix: str) -> S3Path: |
There was a problem hiding this comment.
Independent review (relayed result, Codex): CLEAN
Reviewer and run:
- Reviewer: Codex CLI
codex exec, modelgpt-6-astra, reasoning effortmax, read-only sandbox. Session01a1ea17-a96c-7f72-8213-df19aeecd475. - Scope: a detached snapshot of e9bc32d, reviewing
89ffcd97..e9bc32df7202230fbd41f84c03583a8a06e67d7b. - The prompt stated the agreed contract of Type generated put destinations and document path addressing limits (#1381 step 4) #1404 and the out-of-scope items filed as Share the upload body of put_file() with the async transaction write, and check put sources once #1427, but not the PR, the commit messages or the self-review findings.
- The snapshot and the PR worktree were unchanged afterwards.
- This was a static review: the reviewer ran no tests.
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
_S3BatchTaskscancellation 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.
e9bc32d to
d1789ce
Compare
| ) | ||
| ) | ||
|
|
||
| async def _transfer_pairs( |
There was a problem hiding this comment.
Rebase onto #1398, and independent review of the resolution (relayed result, Codex): FINDINGS (4), repaired in 0ee4e26
Rebase:
- master gained AioS3FileSystem batch operations do not reject conflicting pairs #1398 (cc8f7c4) and Resolve Furo only where a fixed soupsieve installs #1428. AioS3FileSystem batch operations do not reject conflicting pairs #1398 moved
put()'s duplicate-destination check into_put_pairs(), which conflicted with the typed destinations here. - Resolution: AioS3FileSystem batch operations do not reject conflicting pairs #1398's structure is kept. The pairs are built, then the destinations of the files are checked for duplicates. The typed destinations of Type generated put destinations and document path addressing limits (#1381 step 4) #1404 are built inside it, before the check.
- The async
_get()merged AioS3FileSystem batch operations do not reject conflicting pairs #1398's_checked_get_pairs()and its one-at-a-timeoutfiledownloads with_transfer_pairs()unchanged. - AioS3FileSystem batch operations do not reject conflicting pairs #1398's
test_put_directories_with_one_destinationsorted theput_file()destinations, which are nowS3Pathobjects for files named below the root. It compares their strings (d1789ce).
Reviewer and run:
- Reviewer: Codex CLI
codex exec, modelgpt-6.2-astra, reasoning effortmax, read-only. Session01a1fe26-d84b-7a71-b594-ab2c83a750d7. - Scope: a detached snapshot of d1789ce, reviewing
cc8f7c4f..d1789ceewith a focus on how the branch combines with AioS3FileSystem batch operations do not reject conflicting pairs #1398. - This was a static review.
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:
- 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 sameput()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.
- 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
- Medium: the async transfers bypassed
Callback.branch_coro(). fsspec's_put()ran each upload throughcallback.branch_coro(self._put_file)._transfer_pairs()calledbranched()directly, so a callback that overridesbranch_coro()lost its records.- Repair:
_transfer_pairs()runs each transfer throughcallback.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_getand_put) fails at d1789ce.
- Repair:
- Low: the
Raisesofput()/_put()described the version error too narrowly. A local file put directly to a version path also raises, atopen(). Repair: they now say "a destination names a version, also whenrpathnames one and a local file is named below it". - 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 lintandjust benchmark testpass.- 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( |
There was a problem hiding this comment.
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, modelgpt-6.2-astra, reasoning effortmax, read-only. Session01a1fe39-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:
- 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 raisedCancelledErrorto 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_transferfails at 0ee4e26 (the file is uploaded after the cancellation).
- Repair: each transfer's coroutine adds its task to the batch (
- Medium:
_get()returnsNone, 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 returnedNonesince 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). - Low: a skipped
_put()of a single directory callsset_size(0)and returns[], where fsspec returnsNone. 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. - Low: the
Raisesofput()/_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 lintpasses.- The filesystem tests other than
test_s3.py: 1051 passed, 3 skipped. They includetest_s3_async.pyand the fsspec conformance tests, against AWS. test_s3.pyis unaffected (only a docstring changed ins3.py) and passed at 0ee4e26: 720 + 103 passed, 3 skipped.- CI at 0ee4e26 passed.
An independent follow-up of this repair follows.
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>
798b7d3 to
7eb9cd6
Compare
| ) | ||
| ) | ||
|
|
||
| async def _transfer_pairs( |
There was a problem hiding this comment.
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:
- master gained Look up every conflicting source of a move, as of a copy (GH-1397) #1423 (703aaad), which changes the conflict lookups of
S3PathPairing/mv(). - It rebased without textual conflicts.
just lintand the full filesystem suite pass on the rebased branch.
Reviewer and run:
- Reviewer: Codex CLI
codex exec, modelgpt-6.2-astra, reasoning effortmax, read-only. Session01a1fe47-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 enforcesbatch_size, leaves unscheduled pairs idle, and preserves_put()result order."
Findings:
- Medium: deferring
branch_coro()could deadlock a callback. fsspec creates every wrapper before any transfer runs. Withbatch_size=1, a callback that waits in its wrappers until both are created hung on the first file.- Repair:
_transfer_pairs()asksbranch_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_runfails at 798b7d3.
- Repair:
- 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.
- Repair: the wrapper records its cancellation, and the test asserts it right after
- 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.
- This requires a callback whose
Validation at 7eb9cd6, rebased on 703aaad:
just lintandjust benchmark testpass.- The filesystem suite against AWS, in parts: 1052 + 721 + 103 passed, 6 skipped.
- CI at 798b7d3 (before the rebase) passed.
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, andbucket//, are addressed.Behavior before this change (89ffcd9)
The examples use a local file named
x?versionId=v1:put(<file>, "s3://bucket/up/")built the destinationbucket/up/x?versionId=v1, which was parsed as versionv1ofup/x.ValueError: Cannot write to the file with the version specified.putof its directory, formode="create", and for the async_put().Changes
_put_pairs()returns anS3Pathfor 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 newS3Path.with_key_suffix().with_key_suffix()raisesValueErrorfor 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 messageCannot copy to a versioned file.put_file()and the async_put_file()accept anS3Path, also in a transaction of either filesystem._open_path()opens anS3Pathwith the transaction handling ofopen(), andget_file()reads through it too.S3Path.url(),metadata(),getxattr()andsetxattr()of a file now address its bucket, key and version. The filesystems'sign(),metadata(),getxattr()andsetxattr()accept anS3Path.S3Pathof a key such asa/x?versionId=nullsigned, looked up and rewrote thenullversion ofa/x.get()andput()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/filesystem.mdcovers decisions 7, 8 and 10 of the Settle the response models, S3Object, and the listing cache #1341 audit:S3Pathnames it, and the section lists the methods that accept one.fsspec.open(),open_files(),get_mapper().S3Path(bucket, "")is the bucket.S3Pathof 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/forcat_file(),rm_file()and a non-recursivechmod(), and the bucket forinfo()and the listings. A recursivechmod()changes the ACLs of the listed objects, including/, and not that of the bucket. A write raisesValueError. 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.
just lintandjust docs lint;just benchmark test(363 passed, 1 skipped).test_put_names_destinations_after_local_files, sync and async, casesfile,dirandcreate. 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_suffixandtest_with_key_suffix_of_version.TestS3File::test_append_to_path_as_it_is: append mode of anS3Path, 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()andsetxattr()of a file opened with anS3Path. All four fail with the source at 522d2ca.S3Pathpath to the callback as a string: the syncput()destination, the async_put()destination and the async_get()source (3, 3 and 1 tests);S3Pathfile to the transaction (the sync transaction test).tests/pyathena/filesystem/suite against AWS, run locally in parts with a per-test timeout:test_s3.py, including the fsspec conformance tests: 1043 passed, 3 skipped;TestS3FileSystem: 715 passed, 3 skipped;TestS3FileandTestCompressedBuffer: 103 passed.🤖 Generated with Claude Code