Repository navigation
Description
Describe the Bug
When batch-editing records in the Payload admin, @payloadcms/db-postgres calls client.query() on a pg client that is already executing a query. This triggers the following warning:
DeprecationWarning: Calling client.query() when the client is already executing a query
is deprecated and will be removed in [email protected]. Use async/await or an external async flow
control mechanism instead.
This warning is currently masked in Payload's own project templates via NODE_OPTIONS=--no-deprecation in the default dev and start scripts. When that flag is removed (as in any real production deployment that doesn't carry it forward), the warning surfaces.
In [email protected] this will stop warning and start throwing, breaking batch updates entirely.
Link to the code that reproduces this issue
Reproduction Steps
As documented in README.md in linked repo:
1. Start the database
docker compose up -d2. Install dependencies and start the dev server
pnpm install && pnpm devOn first run, onInit seeds the database with:
- Admin user:
[email protected]/password - 3
Dummyrecords withchecked: false
3. Build for production
pnpm build4. Start without deprecation suppression
node --trace-deprecation node_modules/next/dist/bin/next startNote: the default
pnpm startscript passesNODE_OPTIONS=--no-deprecation, which masks the warning. The--trace-deprecationflag surfaces it with a full stack trace.
5. Trigger the bug
- Open
http://localhost:3000/adminand log in as[email protected]/password - Navigate to the Dummy collection
- Select all 3 records using the checkbox in the list header
- Click Edit in the bulk action toolbar
- Set
checkedtotrueand click Save
6. Observe the warning in the terminal
DeprecationWarning: Calling client.query() when the client is already executing a query
is deprecated and will be removed in [email protected]. Use async/await or an external async flow
control mechanism instead.
at Client.query (.../node_modules/pg/lib/client.js:691:7)
at .next/server/chunks/ssr/....js (o.queryWithCache)
at .next/server/chunks/ssr/....js (Object.startActiveSpan)
at .next/server/chunks/ssr/....js (o.execute)
at Object.startActiveSpan
The trace originates in Drizzle's queryWithCache → execute, called via OpenTelemetry's startActiveSpan, ultimately issuing a second pg Client.query() call while the client is already mid-query.
Which area(s) are affected?
db: postgres
Environment Info
Binaries:
Node: 25.1.0
npm: 11.6.2
Yarn: N/A
pnpm: 10.33.0
Relevant Packages:
payload: 3.83.0
next: 16.2.3
@payloadcms/db-postgres: 3.83.0
@payloadcms/drizzle: 3.83.0
@payloadcms/graphql: 3.83.0
@payloadcms/next/utilities: 3.83.0
@payloadcms/richtext-lexical: 3.83.0
@payloadcms/translations: 3.83.0
@payloadcms/ui/shared: 3.83.0
react: 19.2.4
react-dom: 19.2.4
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 25.4.0: Thu Mar 19 19:30:44 PDT 2026; root:xnu-12377.101.15~1/RELEASE_ARM64_T6000
Available memory (MB): 32768
Available CPU cores: 10
Activity
palber commentedon Jun 7, 2026
Hit the same bug, but with localized fields the consequences are much worse — data is permanently deleted.
When running "Edit many" on a collection with localized fields,
*_localesrows of random documents get wiped on every bulk edit. In our case ~44 of 100 product records lost their localized titles per run. On the next edit thoserequiredlocalized fields fail validation — which is when the data loss becomes visible as "X of 100 failed".The reason it's destructive here:
upsertRowtakes a DELETE + reinsert path for localized fields. Under the concurrent-query race on the shared transaction client, the reinserts get lost silently.I suspect the root cause is that
update.jsopens one shared transaction (= one pg client) for the entire bulk op at the top, then fires all documents concurrently viadocs.map(async …). The existingbulkOperationsSingleTransactionflag looks like it was meant to fix this, but it has no effect because the request-level transaction is already open before that flag is consulted.Workaround, with some drawbacks, that fully resolves it for us:
docs: задокументировать известный баг Payload за перемежающимся сбоем…
emmpauldev commentedon Oct 28, 2026
We hit this on a production project (Payload 3.90.2,
@payloadcms/db-postgres3.90.2, pg 8.20.0, drizzle-orm 0.45.2) and measured how widespread it is. The batch update in the original report is only one of several paths. Here are our measurements in case they help scope a fix.How we counted. pg prints the warning once per process, so it hides the volume. We preloaded a small script (
node --require) that wrapspg'sClient.prototype.query. It records the stack each time a query starts while that client already has one active or queued (this._queryQueue.length > 0or an active query). It also keeps the stacks taken at the entry of each Local API call, because drizzle loses the caller's async frames. At exit, it groups the calls by the innermost application frame and by the Payload frame that launched the parallel branch.Payload paths that fan out on the shared transaction client (line numbers in Payload 3.90.2 sources):
fields/hooks/beforeChange/traverseFields.ts:129validates a document's fields in parallel. Each relationship field's validation runs afind(collections/operations/find.ts:213), all on the same transaction client. This fires on any single-documentcreate/updatewith several relationship fields, not just bulk operations. On our demo seed, it accounts for 90 of the remaining concurrent queries.delete({ where }).collections/operations/delete.tsdeletes each matching document in parallel. Each document'sbeforeDelete/afterDeletehooks, plus the per-rowdeleteOne, run concurrently on one client. Any hook that writes (an audit row, for example) adds to the race.update({ where }).collections/operations/update.ts:462is the path in the original report. With user hooks in place, each hook's reads and writes join the race. A single Local APIupdate({ where })over three documents withbeforeValidate/afterChangehooks, the same path as the admin's bulk edit, produced 60 concurrent queries.Counts. These are concurrent queries per run, before and after we removed the sources in our own code. We did three things: (a) one read per save instead of one read per link in a custom
validate, (b) aPromise.allturned into sequential awaits, and (c) cascades that delete their children one by one instead of with one bulkdelete({ where }).After our changes, the application code we control triggers zero concurrent queries. The rest goes through Payload's own fan-out. We can't sequence it from userland short of avoiding bulk operations entirely, and path 1 can't be avoided at all.
A note for anyone relying on bulk delete in hooks. Replacing
delete({ where })withdelete({ id })per child doesn't work as a drop-in inside a parent's transaction. A refused child (anAPIErrorthrown by its hook) rolls back the whole shared transaction and clearsreq.transactionIDbefore the caller can catch it. We kept a bulk call but scoped it to one row (where: { id: { equals } }), which returnserrorsinstead of throwing, and we stop at the first error.Happy to share the preload script if it's useful for reproducing.