Skip to content

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

Open
fornwall wants to merge 3 commits into
apache:mainfrom
fornwall:fix-dbapi-read-partition-cancel
Open

fornwall wants to merge 3 commits into
apache:mainfrom
fornwall:fix-dbapi-read-partition-cancel

Conversation

@fornwall

@fornwall fornwall commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Cancelling the statement does not interrupt connection-owned partition reads or their result streams.

Assisted-by: OpenAI Codex

@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.

@fornwall
fornwall force-pushed the fix-dbapi-read-partition-cancel branch from 892d6d1 to 0c7cd27 Compare November 12, 2026 08:07
… 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>
Assisted-by: OpenAI Codex
…results

Assert that the row iterator created by adbc_read_partition() cancels the
connection, which the SIGINT handler uses during fetches.

Signed-off-by: Fredrik Fornwall <fredrik@fornwall.net>
Assisted-by: OpenAI Codex
@fornwall
fornwall force-pushed the fix-dbapi-read-partition-cancel branch from 0c7cd27 to b5001be Compare November 13, 2026 02:57
Assisted-by: OpenAI Codex
Signed-off-by: Fredrik Fornwall <fredrik@fornwall.net>

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.

🟢 Approval recommended

No active review issues are identified for the cancellation-routing changes.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@fornwall
fornwall requested a review from lidavidm November 13, 2026 03:25
Comment on lines +43 to +46
partitions, _ = cur.adbc_execute_partitions("SELECT 1")
cur.adbc_read_partition(partitions[0])
assert cur._results._cancel == test_dbapi.adbc_connection.cancel
assert cur.fetchone() == (5,)

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.

I'd rather not assert on internals, but if we have to do it, let's make it a new test.

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.

I'd also want to ensure that executing another operation resets _cancel.

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