Repository navigation
fix: a query that fails before it is sent fails the transaction it is in - #177
Merged
Merged
Conversation
okomarov
force-pushed
the
fix/client-failure-aborts-transaction
branch
4 times, most recently
from
October 21, 2026 22:56
f9e87bd to
3029340
Compare
okomarov
force-pushed
the
fix/client-failure-aborts-transaction
branch
11 times, most recently
from
October 22, 2026 12:27
939b9e1 to
0a41adc
Compare
The section listed constraints and exceptions without saying what to configure, and read as if Cloudflare's advice against prepare: false conflicted with the example. It now opens with the three settings (direct connection, prepare left on, max and fetch_types), explains them after, and says Hyperdrive in front of Supavisor's transaction mode fails with either prepare setting (runs 39234865111 and 39236978516). It also drops "not at another pooler's transaction mode", which contradicted CI passing in front of Neon's pooled endpoint.
…it is in Reproduces issue #70 on reserved connections (an undefined value, too many parameters, and a value whose serializer throws after describe, with prepare on and off), with a savepoint, and in sql.begin when the failing query runs after the callback has returned. Also covers the same failures outside a transaction and behind a cursor, which must keep rejecting alone. The Workers edge scenarios run the same cases through Neon, the Supabase pooler and Hyperdrive, with prepare on and off where the target supports prepared statements. Hyperdrive with prepare on closes the connection on a new described statement after an error inside a transaction (cloudflare/workers-sdk#16421), so there the scenario checks that nothing commits rather than for 25P02 and ROLLBACK.
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
force-pushed
the
fix/client-failure-aborts-transaction
branch
from
October 22, 2026 12:57
4159604 to
cd1f85c
Compare
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.
Closes #70.
A query that fails in the client (an
undefinedvalue, 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 laterCOMMITcommitted the other statements without it. The connection now sends a statement the server refuses in the failed query's place, so the transaction fails as it would after a server error:sql.begin(), a failure that lands after the callback returned makesCOMMITanswerROLLBACK, andsql.begin()rejects withTRANSACTION_ROLLED_BACKwhosecauseis the client error;max: 1, the statements after it reject with25P02andCOMMITanswersROLLBACK, as after a server error; a savepoint recovers.The failed query still rejects with its own error, and outside a transaction the queries around it get their own results. Based on porsager#1236 and porsager#1238.
The first commit adds the tests alone, so CI shows them failing on main's code.