fix(adapter-pg): serialize queries on single-connection clients - #29979
fix(adapter-pg): serialize queries on single-connection clients#29979gadcam wants to merge 1 commit into
Conversation
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 <noreply@anthropic.com> Signed-off-by: Camille Barneaud <1693643+gadcam@users.noreply.github.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThe 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. ChangesPostgreSQL query serialization
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
Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Problem
@prisma/adapter-pgemitsDeprecationWarning: Calling client.query() when the client is already executing a querywhenever a query with 2+ sibling relations runs inside a transaction. The query interpreter'sjoinnode loads relations concurrently; apg.Pooltolerates this, but a transaction's singlepg.PoolClientdoes 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.performIOrather than inPgTransaction— the constraint is the single connection, not transactions per se.PrismaPgAdapteropts out via aserializeQueriesflag: 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'sasync-mutexdependency.The interpreter is deliberately untouched: join fan-out stays parallel (a regression test now pins this) and adapters own the serialization.
Tests
client.query()calls (fails without the fix)joinchildren still load in parallelCredit
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
Tests