Skip to content

GH-40502: [Python] Expose NativeFile.abort() - #1

Closed
adrien-grl wants to merge 2 commits into
mainfrom
GH-40502-nativefile-abort
Closed

adrien-grl wants to merge 2 commits into
mainfrom
GH-40502-nativefile-abort

Conversation

@adrien-grl

@adrien-grl adrien-grl commented Sep 29, 2026 •

Copy link
Copy Markdown
Owner

Rationale for this change

Closing an output stream always commits what was written, so a job that fails halfway through still leaves a partial object on S3. Arrow C++ already has Abort() for this, and the S3 stream implements it by aborting the multipart upload, but it wasn't reachable from Python.

What changes are included in this PR?

This adds NativeFile.abort(), which calls FileInterface::Abort() the same way close() calls Close(). The example from the issue now works:

with fs.open_output_stream("bucket/key") as f:
    try:
        do_something_that_may_explode(f)
    except Exception:
        f.abort()
        raise

Are these changes tested?

Yes. test_open_output_stream_abort runs on all the filesystem fixtures, with and without compression and buffering. It checks that nothing is written on S3, and that the mock filesystem sees an abort rather than a close. test_s3_output_stream_abort_after_part_upload aborts after a 10 MiB part has already been uploaded, which I don't think the C++ tests cover. There are also two small tests in test_io.py for aborting in-memory streams.

Backends other than S3 don't discard anything on abort today so the tests are pretty light for the other backends. I ran it against minio, azurite and the GCS testbench. Local, GCS and fsspec keep the written data, since their Abort() just closes. Azure leaves an empty blob, because the blob is created when the stream is opened. Those seem worth separate issues.

test_io.py and test_fs.py pass locally with S3, Azure and GCS enabled.

Are there any user-facing changes?

Yes, NativeFile.abort() is new.

Was AI used for this PR?

In accordance to the AI generation guidelines, please disclose below whether and how AI was used in this PR.

I used Claude Code to write the code, the tests and this description, and to run the tests locally.

PR code and description written by:

  • Human
  • AI

Reviewed before submission by:

  • Human
  • AI
  • Not reviewed

@adrien-grl
adrien-grl force-pushed the GH-40502-nativefile-abort branch from 2a81e57 to 6c0fccb Compare September 29, 2026 09:59
@adrien-grl

Copy link
Copy Markdown
Owner Author

Opened upstream as apache#51631.

@adrien-grl adrien-grl closed this Sep 29, 2026
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.

1 participant