Repository navigation
fix(cockroachdb): preserve structured query results during txn retry replay - #11861
Conversation
CockroachQueryRunner replays stored queries when it hits a 40001 retryable serialization error. Those stored queries were replayed without the original useStructuredResult flag, which can change the returned shape during retries. In practice this can prevent generated values (e.g. primary keys) from being propagated back to entities after a retried INSERT, leaving e.g. post.id undefined. With strict invalidWhereValuesBehavior, that later surfaces as a TypeORMError when building a where condition. This change stores and replays useStructuredResult alongside query+params so retries behave the same as the initial execution.
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
commit: |
PR Code Suggestions ✨Latest suggestions up to e10cc47
Previous suggestionsSuggestions up to commit 1db215c
|
||||||||||||||||||
There was a problem hiding this comment.
Pull request overview
This PR fixes a critical bug in CockroachDB's transaction retry mechanism where the useStructuredResult flag was not preserved during query replay after a 40001 error (transaction retry). This caused INSERT operations to fail to propagate generated IDs back to entities during retries, leading to undefined primary keys and subsequent query failures.
Key Changes
- Added
useStructuredResultfield to the internal query recording structure - Preserved the flag when storing queries during transaction execution
- Restored the flag when replaying queries after transaction rollback
|
Are we closing any issue with this fix? |
Doesn't seem like it, I tried to search but couldn't find any relevant ones |
Summary
CockroachDB transaction retry (40001) replays the recorded queries via
ROLLBACK TO SAVEPOINT cockroach_restart.During that replay, TypeORM was not preserving the original
useStructuredResultflag per query. That can change the return shape of re-executed queries during retries, which in turn can prevent generated values (e.g. primary keys) from being propagated back onto entities after a retriedINSERT.On CockroachDB v24 this shows up in
test/github-issues/9984wherepost.idcan remainundefinedafter a retried transaction, and laterfindOneBy({ id: post.id })fails (especially now that strict handling for undefined where values is enabled).Fix
useStructuredResultalongside{ query, parameters }in the Cockroach retry buffer.useStructuredResultvalue it had originally.Why it’s needed
undefinedidentifiers after a retried write.Tests
github issues > #9984on CockroachDB v24 withinject_retry_errors_enabled=true.