Skip to content

fix(python/adbc_driver_manager): cancel the connection when reading a partition - #4814

Open
fornwall wants to merge 1 commit into
apache:mainfrom
fornwall:fix-dbapi-read-partition-cancel
Open

fornwall wants to merge 1 commit into
apache:mainfrom
fornwall:fix-dbapi-read-partition-cancel

Conversation

@fornwall

@fornwall fornwall commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Cursor.adbc_read_partition() reads through AdbcConnectionReadPartition and the returned stream belongs to the connection, but the cursor cancelled its statement instead: both from the SIGINT handler around the blocking calls and from Cursor.adbc_cancel(). A driver with no active query on the statement treats that as a no-op, leaving the partition read running.

Track the current cancel target on the cursor: the statement after _clear()/execute(), the connection after adbc_read_partition(). Use it for adbc_cancel(), the blocking partition read, and the row iterator that consumes the result stream. Fix the AdbcStatement.cancel docstring, which claimed to cancel the connection.

Test against the Flight SQL test server, whose "forever" query blocks ReadPartition until the client cancels the connection.

AI disclaimer: Created with codex and gpt-6 astra. Iterated on and reviewed by me.

… partition

Cursor.adbc_read_partition() reads through AdbcConnectionReadPartition and
the returned stream belongs to the connection, but the cursor cancelled its
statement instead: both from the SIGINT handler around the blocking calls
and from Cursor.adbc_cancel(). A driver with no active query on the
statement treats that as a no-op, leaving the partition read running.

Track the current cancel target on the cursor: the statement after
_clear()/execute(), the connection after adbc_read_partition(). Use it for
adbc_cancel(), the blocking partition read, and the row iterator that
consumes the result stream. Fix the AdbcStatement.cancel docstring, which
claimed to cancel the connection.

Test against the Flight SQL test server, whose "forever" query blocks
ReadPartition until the client cancels the connection.

Signed-off-by: Fredrik Fornwall <fredrik@fornwall.net>
@fornwall
fornwall requested a review from lidavidm as a code owner September 26, 2026 21:55

@lidavidm lidavidm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Seems reasonable.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Cancellation during subsequent partition-stream fetching remains untested.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Updates Python DB-API cancellation routing so partition reads cancel through their owning connection.

Changes:

  • Tracks the active cancellation target per cursor.
  • Uses connection cancellation for partition reads and stream consumption.
  • Adds Flight SQL cancellation coverage and corrects statement documentation.
File Description
python/​adbc_driver_manager/​adbc_driver_manager/​dbapi.py Routes cancellation to the active statement or connection.
python/​adbc_driver_manager/​adbc_driver_manager/​_lib.pyx Corrects the statement cancellation docstring.
python/​adbc_driver_flightsql/​tests/​test_errors.py Tests cancellation of blocked partition reads.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

)
self._rowcount = -1
self._results = _RowIterator(self._stmt, handle, self._backend)
self._results = _RowIterator(self._cancel, handle, self._backend)

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.

3 participants