Skip to content

fix(client): queries batched after a failing one reject instead of resolving undefined - #30544

Merged
wmadden-electric merged 3 commits into
prisma:v7from
lazerg:fix/issue-30540-batch-failure-undefined
Nov 17, 2026
Merged

wmadden-electric merged 3 commits into
prisma:v7from
lazerg:fix/issue-30540-batch-failure-undefined

Conversation

@lazerg

@lazerg lazerg commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor
await prisma.$transaction(async (tx) => {
  const [created, all] = await Promise.allSettled([
    tx.user.create({ data: { email: '[email protected]' } }), // fails: unique constraint
    tx.user.findMany(),                                       // sent in the same tick
  ])
  // before: created rejected (P2002), all fulfilled with undefined
  // after:  both reject with P2002
})

In Prisma 7, a query that never ran because an earlier query in its batch failed now rejects with that earlier error.

What went wrong

Inside an interactive transaction, queries sent in the same tick are batched together. ClientEngine.requestBatch runs the batch's plans in order and stops at the first failure. It then returned a results array shorter than the list of requests. DataLoader resolves every request past the end of that array with undefined. So queries that never ran looked like they succeeded and returned nothing.

I reproduced this on Postgres 16 with @prisma/adapter-pg, in three ways: a failed $queryRaw followed by more queries, a unique-constraint failure followed by a findMany, and two queries on a transaction that had already rolled back. Every query after the failure resolved undefined.

The fix

requestBatch fills the rest of the results with the error that stopped the batch. So every query that didn't run rejects with the original error code, the same way the whole batch rejects when requestBatch throws. $transaction([...]) still rejects with the original error. A batch of findUniqueOrThrow calls outside a transaction still runs every query, as #29654 made it do.

Tests

  • interactive-transactions functional suite: the new test "batching rejects queries after a failed one within callback" fails on v7 (the findMany resolves undefined) and passes here. It runs against every provider in CI.
  • I reran the Postgres reproduction above with the fix. Every case rejects with the original error code.

Alternatives considered

  • Keep running the remaining plans after a failure. Inside a transaction, the first failure aborts the transaction, so the remaining queries can't succeed anyway.
  • Reject the remaining queries with a new "not run" error. The original error is what the caller needs to act on. A second error code would hide it.

Fixes #30540

@coderabbitai

coderabbitai Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Walkthrough

When a query in an interactive transaction batch fails, requestBatch now adds that error to the results for every query that was not executed. A regression test checks that concurrent queries reject when one query fails.

Changes: Interactive transaction batch error propagation

Layer / File(s) Summary
Propagate batch errors and test concurrent queries
packages/client/src/runtime/core/engines/client/ClientEngine.ts, packages/client/tests/functional/interactive-transactions/tests.ts
requestBatch adds the error for each query left unexecuted after a batch failure. The regression test checks that both concurrent query results reject after a duplicate-email create fails.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: Minimal · up to 92cea

Requests not run after a batch failure now reject instead of resolving as undefined, with a regression test for concurrent interactive-transaction queries. No concrete merge-blocking risk is identified.

Security architecture risk: Minimal · up to 92cea

The fix makes requests that never executed reject instead of appearing successful. It preserves query execution, transaction ownership, and rollback behavior, with no material security risk identified in the changed path.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • observed — The changed operation affects error delivery to the remaining requests in the existing batch. It does not submit those requests to the executor or select a different transaction.

Trust Boundaries and Controls

  • inferred — The inspected path does not introduce an execution-authority transition or a new error transport boundary. It reuses the existing engine-to-request-handler contract and existing error normalization. The appended entries share the caught error object; downstream handling remains the established per-request handling.
Pre-merge checks: Passed 4

Check name Status Explanation
Linked Issues check Passed For directly linked issue [#30540], ClientEngine.requestBatch now appends the failure error for each remaining query when batch execution stops. This prevents omitted results from becoming `undefine…
Out of Scope Changes check Passed The changes stay within [#30540]. The one-line ClientEngine.requestBatch change implements the required batch error propagation. The interactive-transaction test verifies the regression behavior. No…
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title says queries batched after a failing one now reject with an error instead of resolving undefined. The change adds the same error to the results of every remaining query in ClientEngine.reque…
Full details: Linked Issues check

Explanation

For directly linked issue [#30540], ClientEngine.requestBatch now appends the failure error for each remaining query when batch execution stops. This prevents omitted results from becoming undefined and makes those requests reject with the earlier error. The new interactive-transaction regression test uses Promise.allSettled and verifies that both the failing create and the following read reject. The generic batch handling covers the issue's query types, including model and raw requests.

Full details: Out of Scope Changes check

Explanation

The changes stay within [#30540]. The one-line ClientEngine.requestBatch change implements the required batch error propagation. The interactive-transaction test verifies the regression behavior. No unrelated production behavior or unrelated test scope appears in the reviewed change summary.

Full details: Title check

Explanation

The title says queries batched after a failing one now reject with an error instead of resolving undefined. The change adds the same error to the results of every remaining query in ClientEngine.requestBatch when batch execution stops after a failure. The added regression test in the interactive-transactions suite checks that both queries reject after the first query fails. The title names the primary behavior change and matches the linked issue's request. It is specific and follows the expected conventional-commit style.

Finishing Touches

🧪 Generate unit tests (beta)

  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.

ℹ️ Recent review info

⚙️ Run configuration

Configuration used: Repository: prisma/orm/.coderabbit.yml

Review profile: ASSERTIVE

Plan: Advanced

Run ID: e2f6e37f-c608-4cbe-a5b8-029f6b7c17fe

📥 Commits

Reviewing files that changed from the base of the PR and between 9afb1a4 and 92cea8a.

📒 Files selected for processing (2)

  • packages/client/src/runtime/core/engines/client/ClientEngine.ts
  • packages/client/tests/functional/interactive-transactions/tests.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@lazerg

lazerg commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

@wmadden, please have a look when you have time

wmadden-electric and others added 2 commits November 11, 2026 08:25
…the original error

The regression test now asserts that both the failing create and the findMany that
never ran reject with the unique constraint error (P2002), not just that they reject.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric
wmadden-electric enabled auto-merge (squash) November 11, 2026 10:58
@wmadden-electric wmadden-electric changed the title fix(client): reject batched queries that never ran after a failure fix(client): queries batched after a failing one reject instead of resolving undefined Nov 12, 2026
@wmadden-electric
wmadden-electric merged commit f8e30b5 into prisma:v7 Nov 17, 2026
480 of 481 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants