Fix: Do not mutate parameters when serializing in Bind - fixes multiple serialization on retry - #1198
Open
Ne7Le4DeR wants to merge 2 commits into
Open
Conversation
When a prepared query is retried after a FetchPreparedStatement or
RevalidateCachedQuery error, Bind serializes the already serialized
parameters again, corrupting the data:
- json/jsonb values are JSON.stringify'd twice and get stored as strings
- boolean true flips to false ('t' === true is false, so 't' re-serializes to 'f')
- bytea buffers turn into the hex encoding of their previous hex string
The tests cover all three affected built-in serializers on both retry
paths and currently fail; the fix follows in the next commit.
Bind stored each serialized value back into query.parameters, so when a prepared query was retried after a FetchPreparedStatement or RevalidateCachedQuery error, the already serialized values went through the serializers a second time. This corrupted every parameter whose serializer is not idempotent: json/jsonb objects got stored as JSON strings, boolean true silently flipped to false and bytea buffers were hex-encoded twice. Serialize into a local variable instead and leave query.parameters untouched.
Ne7Le4DeR
force-pushed
the
fix/double-serialization-on-retry
branch
from
August 21, 2026 18:37
90f68d0 to
7f70f8c
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.
Fixes #1197
Bindstored each serialized value back intoquery.parameters, so when a prepared query was retried after aFetchPreparedStatementorRevalidateCachedQueryerror, the already serialized values went through the serializers a second time:json/jsonbobjects got stored as JSON strings,boolean truesilently flipped tofalse, andbyteabuffers were hex-encoded twice. See #1197 for the full mechanism and a standalone reproduction.Serialize into a local variable instead and leave
query.parametersuntouched - the retry itself is unchanged and still transparent, it just binds the original values now.