Repository navigation
Description
Problem
The independent reviews of the 4.x backports (#1552, #1553, #1560) found defects in the master changes themselves. The backports keep master's code, so the fixes go to master first and are then backported. Each item below is on master at abe633c. Items marked verified were checked against the code or reproduced; the others are static review findings that the fixing PR has to confirm first.
1. get() destination check (#1516)
- An existing local directory skips the check of its source (verified by reading the code).
S3FileSystem._check_local_destinations()skips a destination that is an existing directory (pyathena/filesystem/s3.py:3302) before it asks whether its S3 source is a file. Without/kalready a directory,get(["bucket/k/child", "bucket/k"], ["out/k/child", "out/k"], batch_size=1)downloadschildand then raisesIsADirectoryErrorfromget_file()fork, instead ofValueErrorbefore any download. Not a regression: before Reject get() files that other destinations lie below and keep folder markers as directories (GH-1487) #1516 the same call also ended inIsADirectoryError. bytesandstrspellings of one path are not compared.os.path.realpath()keeps the type of its argument (s3.py:3305), so[b"/tmp/out/k", "/tmp/out/k/child"]passes the ancestor check:kis written, and the child's parent directory then fails.- A listed source must be hashable.
rp in directories(s3.py:3347) raisesTypeErrorfor astrsubclass with__hash__ = None, even when the set is empty; such a source downloaded before Reject get() files that other destinations lie below and keep folder markers as directories (GH-1487) #1516.
2. invalidate_cache() docstring (#1481)
Verified. The docstring says that a path ending in slashes is invalidated with and without them (s3.py:4933). Since #1481, the slashes after a version ID belong to it: invalidating bucket/key?versionId=v1/ evicts the version v1/ and keeps v1, as test_s3.py checks. The docstring needs that exception.
3. S3Path pickles with an empty version ID (#1534)
Verified (the dataclass state is restored without __post_init__). S3Path.__post_init__() (pyathena/filesystem/s3_path.py:79) stores an empty version ID as None, but unpickling does not call it. An S3Path("bucket", "k", "") pickled by v4.3.0 keeps version_id="" when it is loaded, so it compares unequal to S3Path("bucket", "k"), and move_pairs() can accept two sources whose destinations are that one object.
4. Concurrent close() of AioS3StreamedFile (#1541)
Two tasks close a file opened for writing. The first close is cancelled while its PutObject runs, and S3 then answers AccessDenied. The first task waits for the request and raises its cancellation, but _close_once() (pyathena/filesystem/s3_async.py:2889) hands None to the second task, which returns as if the object had been written.
5. Docs and docstrings of the read path (#1541)
docs/filesystem.md:184says that awrite()that takes nothing fails the download withOSError. A non-blocking raw stream whosewrite()returnsNoneis not supported (S3File._write_all(),s3.py:6499, countsNoneas all of the data), which Fix the read path of S3 files (GH-1517) #1541 states but the guide does not.- The
S3File.__reduce__docstring says that the reopened file reads the same object (s3.py:5658). With version awareness off, a literal key that looks like a version, such asS3Path("bucket", "x?versionId=null"), is reparsed on reopen as thenullversion ofx. The filesystem guide already documents this; the docstring does not.
6. Tests
test_batch_conflicting_pairs(test_s3.py): the upload collision pairs3://bucket/aandbucket/ais already equal after the protocol is stripped. A pair that is equal only once parsed, such ass3::s3://bucket/aandbucket/a, is not covered, so a comparison of strings would pass the test (Pair tuples as lists and align put() progress with _put() (GH-1482) #1498).test_get_file_with_destinations_below_it(sync and aio) andtest_writer_invalid_block_size(test_s3_writer.py) match exception messages that are not documented; the exception type and the absence of writes are the contract (Reject get() files that other destinations lie below and keep folder markers as directories (GH-1487) #1516, Move the filesystem helpers to the objects they operate on (GH-1453) #1480). See docs/testing.md "Choose what to test".test_read_in_stopped_scope(test_s3_async.py): with three ranges and two workers, the executor already rejects the third range before the file's read, so the test passes without the per-request check that Fix the read path of S3 files (GH-1517) #1541 added.test_open_s3_additional_kwargs_none(test_s3_async.py): checks the stored encryption setting without an upload, so awbopen that drops it would pass.test_read_non_positive_block_size(aio) andtest_open_read_non_positive_block_size(sync): a reintroduced endless range split hangs or exhausts the worker instead of failing; they need a bound.
Reproduction
Items 1.1 and 3 are reproducible offline: item 1.1 with a local directory out/k and a fake S3 holding k and k/child; item 3 by pickling an S3Path whose version_id is set to "" through object.__setattr__ and loading it. The other items come from reading the code and need a reproduction in the fixing PR.
Environment
master abe633c; also on 4.x after the backports #1552, #1553 and #1560.
Proposed fix (optional)
One PR on master that confirms each item, fixes the confirmed ones (or records why one is not changed), and is then backported to 4.x with the other fixes. Item 4 is the only one that can report success for a failed write; it comes first.
Activity
laughingman7743 commentedon Nov 30, 2026
One more item, from the independent follow-up review of #1560 (static; not yet confirmed):
5.3.
pipe_file()docstring on transactionsThe
S3FileSystem.pipe_file()docstring (masterpyathena/filesystem/s3.py:3709) says that writes inside an fsspec transaction go through the buffered path, "which uploads the data as a parallel multipart upload". With the default block size, a one-bytepipe_file()insidefs.transactionstays buffered until the commit, which sends a single PutObject.laughingman7743 commentedon Nov 30, 2026
One more item, from the independent review of the
4.xbackport #1568 (static; not yet confirmed):6.6.
placeholder_connection()docstringThe test helper
placeholder_connection()(tests/pyathena/util.py, its**kwargsfrom 4062ca1, #1544) says "Building it sends no request to AWS." That holds for the default arguments, but it forwards connection arguments:placeholder_connection(role_arn="arn:aws:iam::123456789012:role/test")attemptsAssumeRolewhile the connection is built. The docstring should limit the guarantee to arguments that make no request.laughingman7743 commentedon Nov 30, 2026
More items, from the independent review of the
4.xbackport #1578 (static; not yet confirmed). The code, docs and tests are the same on master.6.7. SQLAlchemy 2.1 in the compliance suite (#1566)
tests/sqlalchemy/test_suite.py(the quantifier test,(True, False, True, False)) expects SQLAlchemy 2.0's result for~(any_(flags) == True). SQLAlchemy 2.1 negates the wholeany_match, which gives(True, False, False, False)forflags = [True, False]. #1566 updated the compile-only test for this difference, but not the live compliance test.6.8.
fsspec.open_files()and bucket versions (#1551)docs/filesystem.md(master line 779) listsfsspec.open_files()among the compositions that raiseValueErrorfor a bucket path with a version. Its default expansion globs?, so with onlyXversionId=v1in the bucket,fsspec.open_files(["s3://bucket/?versionId=v1"])returns a reader for that object.6.9. Engine option coverage (#1567)
The consolidated engine test in
tests/pyathena/sqlalchemy/test_base.pyno longer checks thatduration_secondsandverifyreach the DB-API connection; the removedtest_conn_str_duration_secondsandtest_conn_str_verifydid. A connection that droppedduration_seconds=1800after the URL conversion would pass the replacement tests.6.10. Exception wording in #1551's tests
tests/pyathena/filesystem/test_s3.pyandtest_s3_path_pairing.py(the bucket-version cases) match undocumented exception messages; the type and the absence of requests are the contract.laughingman7743 commentedon Nov 30, 2026
Two more items, from the independent follow-up review of the
4.xbackport #1578, which now includes a8afdaa (#1538 item 1). Both are on master too.7.
cp_file()of a directory path depends on the listing cache (a8afdaa)Verified offline with
serve_s3_keys(fs, {"dir/child"}):cp_file("s3://bucket/dir/", "s3://bucket/dst")skips the directory on a cold cache (HeadObject, ListObjectsV2), but afterfs.ls("s3://bucket/dir")it raisesFileNotFoundError: bucket/dir/without a request: the cached listing holdsdir/childand no entry fordir/, and the lookup of the parsed source answers from it before the prefix check. Before a8afdaa, both calls skipped the directory. Same on master 0255e1f and on the current master; the async copy shares the lookup.8.
bucket//writes (docs)docs/filesystem.md("Bucket paths with a trailing double slash", master line 794) says that a write tos3://YOUR_S3_BUCKET//, "such aspipe_file()", raisesValueError.cp_file("s3://bucket/src", "s3://bucket//")sends CopyObject with the destination key/; only the writes that strip the trailing slashes, such aspipe_file(), raise.laughingman7743 commentedon Nov 30, 2026
More items, from the independent review of the
4.xbackport #1591 (thediscard()part of #1539; static, not yet confirmed).S3File.discard(), thewrite()docstring, the guide's paragraph and the tests are the same on master.9. An interrupted
discard()can commit an empty object (#1539)discard()drops the buffer and marks the file closed before_abort_write()changes the write session. For a closedautocommit=Falsefile that holdsb"abc"for a deferred commit, an interrupt (Ctrl-C) on entry to_abort_write()leaves the sessionIDLEwithout the data; if the caller catches it and the transaction then commits,commit()sends an empty PutObject. The session should refuse the commit before the buffer is released.10.
discard()with a pool executor of the calling thread (#1539)A worker of an
S3ThreadPool(1)that uses that pool as anS3File'sexecutor, writes insidewithand callsdiscard():discard()shuts the pool down withwait=False, and thewithexit's_close()callsshutdown(wait=True), so the worker joins itself and raisesRuntimeError.11.
discard()docs (#1539)S3File.write()docstring listsS3MultipartStateErroronly afterflush(force=True), but after an explicitcommit()of an open file the nextwrite()raises it too; withautocommit=False, aflush(force=True)alone leaves the file open and uncommitted, and the nextwrite()raisesValueError.discard()makes a laterclose()commit nothing; a write thatflush(force=True)already committed (autocommit, multipart) stays committed, anddiscard()sends no abort. "an uncommitted write" would say it.12.
discard()tests (#1539)_close_without_commit()and thenclose()on the same handle, so a regression in either path is masked by the other.discard()write()test matches fsspec's message ("not in write mode"); the exception type is the contract.laughingman7743 commentedon Nov 30, 2026
Item 9 is verified offline (
serve_s3_keys;fs.open(..., "wb", autocommit=False),write(b"abc"),close(), thendiscard()with an interrupt raised on entry to the abort, thencommit()):commit()sendsPutObjectwithout a body, so the object becomes empty.4.x13dc02b (before thediscard()backport [4.x] Backport the discard() part of #1539 #1591): the interrupt arrives in_S3WriteSession.abort(), the buffer is still there, andcommit()sendsPutObjectwithb"abc".So #1539's
discard()turns this interrupted case from committing the written data into committing an empty object. It is the first item to fix; the4.xbackport ofdiscard()(#1591) waits for that fix.laughingman7743 commentedon Nov 30, 2026
More items, from the independent review of the
4.xadaptation of #1559 (#1594; static, not yet confirmed). Master'sAthenaDialect.connect()/initialize()(#1559) has the same code.13. Connection arguments of #1559 (
pyathena/sqlalchemy/base.py)connect()keeps thecparamsdict of each connection, whose nested dicts (tblproperties,serdeproperties,cursor_kwargs) are shared with the arguments of later connections. Ado_connecthandler of a later connection that changescparams["cursor_kwargs"]["s3_staging_dir"]in place changes the options that DDL takes from the first connection.create_connect_args()outside the pool, concurrent with the first connection, can see_connectedfalse and replace the options right afterinitialize()set them.weakref.ref(connection, ...)raisesTypeErrorfor a DB-API connection that cannot be weakly referenced, such as a proxy with__slots__and no__weakref__returned by a module passed withcreate_engine(module=...), so the first connection fails even if no DDL is compiled.laughingman7743 commentedon Nov 30, 2026
One more item, from the independent follow-up review of #1594 (static, not yet confirmed):
13.4.
test_create_table_takes_arguments_of_initializing_connection(#1559)The test closes the second connection, created in a
first_connectlistener, before the dialect is initialized, so its weak-reference callback removes its pending entry; an implementation that takes the latest pending arguments (popitem()) also passes. It also relies onfirst_connectrunning beforeDialect.initialize(). Keeping the second connection open until the checkout ends (for example from ado_connecthandler that creates both and returns the first) would distinguish them.laughingman7743 commentedon Nov 30, 2026
Items 9 to 12 (the
discard()findings of #1539) move to #1628, which is in the 5.0.0 milestone: item 9 is a master-only regression against 4.4.0 and blocks 5.0.0. The remaining items stay here for 5.0.1; the4.xbackport #1591 now waits for #1628.