Repository navigation
Close a cursor when its last row is read - #31
Merged
Merged
Conversation
A cursor opened outside a transaction starts its own, committed on close. Iterating to the end left it open, so every later statement on the connection ran inside that transaction and was rolled back when the connection closed: `for row in Postgres.cursor(conn, sql) ... end` or `Tables.columntable(cursor)` followed by an INSERT silently lost the INSERT. Reading past the last row now closes the cursor (portal released, own transaction committed); `close!` afterwards is a no-op, and a caller-owned transaction stays open. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
quinnj
referenced
this pull request
Oct 27, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A cursor opened outside a transaction starts its own (
BEGIN), committed only byDBInterface.close!(cursor). Iterating a cursor to the end left that transaction open, so every later statement on the connection ran inside it, reported success, and was rolled back when the connection closed:Reading past the last row now closes the cursor: the portal is released, the cursor's own transaction is committed (what
close!already did), and an owned prepared statement is closed. A laterclose!is a no-op, and a transaction the caller opened stays open. Rows already returned stay valid (eachResultRowowns its values).Not covered: a cursor abandoned with
breakkeeps its transaction open untilclose!, as documented. The docstring now says that every statement runs inside the cursor's transaction until then.Verification: "Cursor Streaming" now checks that a full read and
Tables.columntable(cursor)leave no transaction open and that a later INSERT autocommits, and that the named-portal test sees the portal released at the last row with the caller's transaction still open (9 assertions fail on main); fullPkg.test()passes locally (8854/8854).🤖 Generated with Claude Code