GeezerVison is showing github.com — fix(adapter-pg): serialize queries on single-connection clients by gadcam · Pull Request #29979 · prisma/orm
Conversation
gadcam
commented
Aug 11, 2026
•
edited by coderabbitai
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
Problem
@prisma/adapter-pg emits DeprecationWarning: Calling client.query() when the client is already executing a query whenever a query with 2+ sibling relations runs inside a transaction. The query interpreter's join node loads relations concurrently; a pg.Pool tolerates this, but a transaction's single pg.PoolClient does not — and pg@9 will make it a hard error.
Fixes #29407.
Fix
Per @aqrln's review on #29468, serialization is done in the base PgQueryable.performIO rather than in PgTransaction — the constraint is the single connection, not transactions per se. PrismaPgAdapter opts out via a serializeQueries flag: the pool manages its own concurrency, and serializing it would cap the whole application at one query at a time. A small promise-chain lock replaces #29468's async-mutex dependency.
The interpreter is deliberately untouched: join fan-out stays parallel (a regression test now pins this) and adapters own the serialization.
Tests
- transaction connection never sees overlapping
client.query() calls (fails without the fix)
- pool queries stay parallel — guards against reintroducing a global bottleneck
- a failed query releases the lock, so an error can't deadlock the rest of the transaction
- interpreter:
join children still load in parallel
Credit
This supersedes #29468 by @matingathani, who identified the issue and proposed the original mutex approach — picking it up as the review feedback has been open since 2026-07-28. Thanks also to @tensordreams for their contributions to that branch.
🤖 Generated with Claude Code
Summary by CodeRabbit
-
Bug Fixes
- Improved transaction query handling so queries execute sequentially and continue correctly after a query failure.
- Preserved concurrent query execution for connection pools and join-related child queries.
-
Tests
- Added coverage for transaction serialization, pool concurrency, failure recovery, and concurrent join queries.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
wolfcreative and Leko reacted with thumbs up emoji
|
All committers have signed the CLA.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
coderabbitai
Bot
commented
Aug 11, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|

Important
Review skipped
Review was skipped as selected files did not have any reviewable changes.
⚙️ Run configuration
-
- Configuration used: Repository: prisma/orm/.coderabbit.yml
- Review profile: ASSERTIVE
- Plan: Advanced
- Run ID:
55f22cb0-41cb-4b3b-803f-f88db330a591
📥 Commits
-
Reviewing files that changed from the base of the PR and between 8537b42 and 79a7142.
You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.
Use the checkbox below for a quick retry:
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
-
⚙️ Run configuration
-
Configuration used: Path: .coderabbit.yml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: b3ada4f8-cf96-47cd-8b43-6240edba9fc9
📥 Commits
-
Reviewing files that changed from the base of the PR and between 7139956 and 9adde52.
📒 Files selected for processing (3)
-
packages/adapter-pg/src/__tests__/pg.test.ts
packages/adapter-pg/src/pg.ts
packages/client-engine-runtime/src/interpreter/query-interpreter.test.ts
📝 Walkthrough
-
Walkthrough
The PostgreSQL adapter now serializes queries for single-client transactions, preserves serialization after failures, and allows pool adapters to remain concurrent. Tests cover transaction ordering, pool concurrency, failure recovery, and concurrent join child queries.
Changes
PostgreSQL query serialization
| Layer / File(s) |
Summary |
Serialization policy and failure-safe execution packages/adapter-pg/src/pg.ts, packages/adapter-pg/src/__tests__/pg.test.ts |
PgQueryable queues single-client queries and continues the queue after failures. PrismaPgAdapter disables serialization for pools. Tests cover serialized transactions and concurrent pool queries. |
Join child-query concurrency validation packages/client-engine-runtime/src/interpreter/query-interpreter.test.ts |
A regression test verifies that three join child queries execute concurrently. |
Estimated code review effort: 3 (Moderate) | ~20 minutes
Sequence Diagram(s)
sequenceDiagram
participant QueryInterpreter
participant PgQueryable
participant pgClient
QueryInterpreter->>PgQueryable: performIO(query)
PgQueryable->>pgClient: execute one queued query
pgClient-->>PgQueryable: return result or failure
PgQueryable-->>QueryInterpreter: return result
Loading
Possibly related PRs
- prisma/prisma#29839: Both changes address PostgreSQL query serialization, failure-safe locking, and pool concurrency.
- prisma/prisma#29954: Both changes modify
PgQueryable.performIO and PostgreSQL transaction lifecycle handling.
Suggested labels: lgtm
Suggested reviewers: jacek-prisma, aqrln
Mergeability Score: ⚪ Minimal · up to 9adde
The change is localized to query serialization and its associated tests; no actionable merge-blocking risk remains beyond normal checks and review.
🚥 Pre-merge checks | ✅ 5
-
✅ Passed checks (5 passed)
-
| Check name |
Status |
Explanation |
| Description Check |
✅ Passed |
Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check |
✅ Passed |
The title clearly describes the primary change: serializing queries for single-connection PostgreSQL clients. |
| Linked Issues check |
✅ Passed |
The changes prevent overlapping queries on single clients, preserve pool concurrency, and test failure recovery and parallel relation queries for [#29407]. |
| Out of Scope Changes check |
✅ Passed |
All code and tests support query serialization, pool concurrency, failure recovery, or parallel relation-query behavior. |
| Docstring Coverage |
✅ Passed |
No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. |
✨ Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create PR with unit tests
Comment @coderabbitai help to get the list of available commands.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
|
|
return this.#performIO(query)
|
|
|
}
|
|
|
const previous = this.#queryLock
|
|
|
const current = previous.then(() => this.#performIO(query))
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will reject all pending queries with the exact same error if a previous query in the chain fails, which sounds undesirable
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The previous version did isolate errors (the stored chain was always current.catch(() => {}), so a failure only rejected its own caller; the "keeps serializing after a failed query" test covers exactly this scenario).
That said the code did not express well this intent : the lock is now a resolve-only Promise<void> that just signals completion of the previous query, so an error structurally can't enter the chain.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
@aqrln could you approve the CI run when you get a chance please?
All three review comments are addressed and tests pass locally, but workflows haven't run on the PR yet.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
@aqrln I hope you are doing well !
Your comments have been addressed
Can you approve the CI run when you get a chance please?
I think it is the main thing we can do to check if this could potentially be merged.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
A pg.PoolClient is a single connection and does not support concurrent
queries (deprecated in pg@8, an error in pg@9), but the query interpreter
loads sibling relations concurrently, so any query with 2+ relations
inside a transaction triggered the deprecation warning. Serialize
performIO in PgQueryable for single-connection clients, leaving the
pool path parallel.
Supersedes prisma#29468, fixes prisma#29407.
Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: Camille Barneaud <[email protected]>
Restructure the serialization lock so it can never carry a query's
error: the lock promise only signals completion, and a failed query
rejects its own caller only. Use timers.setImmediate() in tests and
derive the join-child type from the query plan instead of asserting.
Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: Camille Barneaud <[email protected]>
|
Confirming this on @prisma/[email protected] / [email protected] / Node 22.14.0.
The diagnosis in this PR matches what I see: the warning fires on a multi-relation read inside $transaction, not on pool queries. Prisma 7.10.0 still reproduces it, so #29650 (duplicate values arg) did not address this path; worth noting since #29646 attributes the warning to that cause.
Minimal shape that triggers it here, a nested include inside an interactive transaction:
await prisma.$transaction(async (tx) =>
await tx.item.update({
where: { id },
data: { status: 'ACTIVE' },
include: { acounts: { include: { liability: true } } },
});
});
Emitted once per process, as expected for util.deprecate.
What makes this more than cosmetic: pg@9 turns the deprecated path into a hard error, so the warning is a forward-compatibility signal rather than noise. Applications can't fix it themesleves -- the client.query() calls are inside the adapter.
Happy to test a build of this branch against a real app if that's useful.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
@SevInf could you take a look when you have a chance?
aqrln reviewed earlier (all comments addressed) but hasn't been able to get to the CI approval, this should be ready to merge.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
acchievenattwuts-tech
pushed a commit
to acchievenattwuts-tech/autoparts
that referenced
this pull request
Oct 1, 2026
…g@9 hold
- previewSupplierDebitNote no longer console.errors a ZodError (incomplete
form, e.g. missing reason); it still rethrows so the action returns the
Thai message, and every other failure still logs.
- Golden test: incomplete form logs nothing, a service failure still logs.
- PLAN.md: post-lifecycle-fix [db-retry] results (0 gave-up, diagnostics
kept), hold pg at 8.x until prisma/orm#29979 lands (Prisma 7 join node
runs include relations concurrently on one transaction connection), and
the Z1-Z3 deploy result line.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
acchievenattwuts-tech
pushed a commit
to acchievenattwuts-tech/autoparts
that referenced
this pull request
Oct 5, 2026
…g connection
Prisma 7 loads sibling relations (2+ in one include / nested select) with
Promise.all. Inside an interactive transaction they share one pg connection,
so pg@8 queued them and logged "DeprecationWarning: Calling client.query()
when the client is already executing a query" (credit-note create/edit on
2026-10-04, via rebuildCreditNoteProfitFacts); pg@9 makes it an error.
FluidPrismaPg now wraps each transaction's queryRaw/executeRaw in a
resolve-only promise queue, mirroring prisma/orm#29979. Pool queries outside
a transaction stay concurrent. The golden test runs Prisma's real query
interpreter against a fake connection; its canary fails once
@prisma/adapter-pg serializes by itself, signalling the wrapper can go.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@wmadden could you approve the CI run when you get a chance?
The branch is up to date with v7 (now that #30668 fixed CI there), and the review comments were addressed on Aug 13. Thanks a lot!
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This branch has not been deployed
No deployments
Reviewers
aqrln
Awaiting requested review from aqrln
At least 1 approving review is required to merge this pull request.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.
|