Fix stale fieldsCache in withPgDebug across AtOnce queries#803
Merged
LaurentRDC merged 1 commit intohaskell-beam:masterfrom Apr 23, 2026
Merged
Conversation
…eam#802) renderExecReturningList called cachedGetFields but then freed the result via unsafeFreeResult, allowing libpq to reuse the pointer address on the next Pg.exec. A subsequent query with different column types would get a false cache hit and inherit stale field OID metadata, causing a BeamRowReadError on column 0. Fix: renderExecReturningList calls getFields directly. The cache remains for stepProcess (CursorBatching), where it is safe and beneficial. Regression test added to beam-postgres-tests. Fixes haskell-beam#802, regression introduced in haskell-beam#797. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Member
|
Ooof, thanks for sending a patch. This is very unfortunate |
Member
|
beam-postgres-0.5.6.0 has been deprecated in Hackage. I'm preparing release 0.5.6.1 which will include this fix. It will be released tomorrow |
Contributor
Author
|
Thank you! |
Member
|
|
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.
Summary
renderExecReturningList(theAtOncepath) was callingcachedGetFieldsand then freeing the result viaPg.unsafeFreeResult. libpq can reuse the freed pointer address on the nextPg.exec, causing the next query to get a false cache hit and inherit stale field OID metadata from the previous query.renderExecReturningListnow callsgetFieldsdirectly. ThecachedGetFieldsone-entry cache is preserved forstepProcess(CursorBatching), whereunsafeFreeResultis never called and the cache is both safe and beneficial (avoidsgetFieldsper row within a 256-row batch).TEXTvsINT4) queried in sequence within onerunBeamPostgrescall.Fixes #802. Regression introduced in #797.
Test plan
cabal test beam-postgres-tests --test-options="--pattern fieldsCache"passescabal test beam-postgres-testspasses🤖 Generated with Claude Code