Repository navigation
Conversation
…cribe
A query with parameters that is new to a connection is sent as Parse and
Describe first, and only bound once the server has described its
parameter types. If a parameter then fails to serialize (for example
`new Date(NaN)`, whose serializer throws a RangeError), the query is
rejected and a bare Sync is sent. The server answers that Sync without an
error, so a transaction the query was pipelined in goes on and commits
without it:
const reserved = await sql.reserve()
await Promise.all([
reserved`begin`,
reserved`insert into test values (1)`,
reserved`select ${ new Date(NaN) }::timestamptz`, // rejects
reserved`insert into test values (2)`,
reserved`commit` // commits 1 and 2
])
Bind the query with no parameters instead. The server refuses it, since
the query takes at least one parameter (or it would not have been
described first). That aborts the transaction, the refusal answers in the
query's place, and the query is rejected with its own error, as a retried
query already is. It is no longer a cursor either, whose error would send
a Sync of its own and shift the next answer.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Author
|
I made a few PRs from Claude which fix some problems I was having. Can you take a look? |
okomarov
added a commit
to steadybrew/postgresjs
that referenced
this pull request
Oct 21, 2026
A query that failed in the client (an undefined value, too many parameters, a serializer that throws, a helper that fails to build) was rejected alone and never reached the server, so an open transaction carried on and a later COMMIT committed the other statements without it. The connection now sends a statement the server refuses in the failed query's place, with its own Sync, and keeps the query in the line with its own error to report, so answers stay aligned and the transaction fails as after a server error: sql.begin() rejects with TRANSACTION_ROLLED_BACK whose cause is the client error, and a transaction run by hand gets 25P02 until a savepoint rolls it back. The same applies when a value fails to serialize after the server described the statement. Outside a transaction only the failing query rejects, as before. Closes #70. Based on porsager#1236 and porsager#1238.
okomarov
added a commit
to steadybrew/postgresjs
that referenced
this pull request
Oct 21, 2026
A query that failed in the client (an undefined value, too many parameters, a serializer that throws, a helper that fails to build) was rejected alone and never reached the server, so an open transaction carried on and a later COMMIT committed the other statements without it. The connection now sends a statement the server refuses in the failed query's place, with its own Sync, and keeps the query in the line with its own error to report, so answers stay aligned and the transaction fails as after a server error: sql.begin() rejects with TRANSACTION_ROLLED_BACK whose cause is the client error, and a transaction run by hand gets 25P02 until a savepoint rolls it back. The same applies when a value fails to serialize after the server described the statement. Outside a transaction only the failing query rejects, as before. Closes #70. Based on porsager#1236 and porsager#1238.
okomarov
added a commit
to steadybrew/postgresjs
that referenced
this pull request
Oct 21, 2026
A query that failed in the client (an undefined value, too many parameters, a serializer that throws, a helper that fails to build) was rejected alone and never reached the server, so an open transaction carried on and a later COMMIT committed the other statements without it. The connection now sends a statement the server refuses in the failed query's place, with its own Sync, and keeps the query in the line with its own error to report, so answers stay aligned and the transaction fails as after a server error: sql.begin() rejects with TRANSACTION_ROLLED_BACK whose cause is the client error, and a transaction run by hand gets 25P02 until a savepoint rolls it back. The same applies when a value fails to serialize after the server described the statement. Outside a transaction only the failing query rejects, as before. Closes #70. Based on porsager#1236 and porsager#1238.
okomarov
added a commit
to steadybrew/postgresjs
that referenced
this pull request
Oct 22, 2026
A query that failed in the client (an undefined value, too many parameters, a serializer that throws, a helper that fails to build) was rejected alone and never reached the server, so an open transaction carried on and a later COMMIT committed the other statements without it. The connection now sends a statement the server refuses in the failed query's place, with its own Sync, and keeps the query in the line with its own error to report, so answers stay aligned and the transaction fails as after a server error: sql.begin() rejects with TRANSACTION_ROLLED_BACK whose cause is the client error, and a transaction run by hand gets 25P02 until a savepoint rolls it back. The same applies when a value fails to serialize after the server described the statement. Outside a transaction only the failing query rejects, as before. The upgrade note leads with the half-committed transaction this prevents and says upgrading leaves data written that way in place. Closes #70. Based on porsager#1236 and porsager#1238.
okomarov
added a commit
to steadybrew/postgresjs
that referenced
this pull request
Oct 23, 2026
A query that fails before it reaches the server now fails the transaction it is in (issue #70). The reserved-connection pipeline tests for an undefined value and too many parameters reproduce porsager#1236, and the serialize-after-describe tests with prepare on and off reproduce porsager#1238. On 3.4.9 each commits both inserts without the failed statement or hangs on the shifted answers; on the fork the transaction rolls back.
okomarov
added a commit
to steadybrew/postgresjs
that referenced
this pull request
Oct 24, 2026
A query that fails before it reaches the server now fails the transaction it is in (issue #70). The reserved-connection pipeline tests for an undefined value and too many parameters reproduce porsager#1236, and the serialize-after-describe tests with prepare on and off reproduce porsager#1238. On 3.4.9 each commits both inserts without the failed statement or hangs on the shifted answers; on the fork the transaction rolls back.
Owner
|
Thanks! This is part of v4 (06cf284), so I am closing it here. The changelog has the details: https://github.com/porsager/postgres/blob/master/CHANGELOG.md |
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 query with parameters that is new to a connection is sent as Parse and Describe first, and only bound once the server has described its parameter types. If a parameter then fails to serialize (for example
new Date(NaN), whose serializer throws a RangeError), the query is rejected and a bare Sync is sent. The server answers that Sync without an error, so a transaction the query was pipelined in goes on and commits without it:Bind the query with no parameters instead. The server refuses it, since the query takes at least one parameter (or it would not have been described first). That aborts the transaction, the refusal answers in the query's place, and the query is rejected with its own error, as a retried query already is. It is no longer a cursor either, whose error would send a Sync of its own and shift the next answer.