Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The error is incorrectly pointed out when using the $transaction method #14373

Closed
aya-eiya opened this issue Jul 19, 2022 · 2 comments · Fixed by #16240
Closed

The error is incorrectly pointed out when using the $transaction method #14373

aya-eiya opened this issue Jul 19, 2022 · 2 comments · Fixed by #16240
Assignees
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. tech/typescript Issue for tech TypeScript. topic: $transaction Related to .$transaction(...) Client API topic: transaction
Milestone

Comments

@aya-eiya
Copy link

aya-eiya commented Jul 19, 2022

Bug description

When multiple update queries are set to the $transaction method and an error occurs in one of them, it is always indicated that the first query in the array of arguments has failed.

How to reproduce

https://github.com/aya-eiya/prisma-tx-error

schema.prisma

datasource db {
  provider = "sqlite"
  url      = "file:./dev.db"
}

generator client {
  provider = "prisma-client-js"
}

model User {
  id        Int      @id @default(autoincrement())
  email     String   @unique
  memo      String?
  createdAt DateTime @default(now())
}

main.js

const { PrismaClient } = require('@prisma/client')

async function main() {
  const prisma = new PrismaClient()
  await prisma.user.deleteMany({})
  await prisma.$transaction([
    prisma.user.updateMany({
      where: {
        email: {
          contains: '@corp.com',
        },
      },
      data: {
        memo: 'corp',
      },
    }),
    prisma.user.update({
      where: {
        id: 1,
      },
      data: {
        memo: 'id is 1',
      },
    }),
  ])
}

main()

This script will get

./src/main.js:7:17

   4 const prisma = new PrismaClient()
   5 await prisma.user.deleteMany({})
   6 await prisma.$transaction([
→  7   prisma.user.updateMany(
  An operation failed because it depends on one or more records that were required but not found. Record to update not found.
    at RequestHandler.handleRequestError (/Users/aya-eiya/Work/prisma/node_modules/@prisma/client/runtime/index.js:49670:13)
    at RequestHandler.request (/Users/aya-eiya/Work/prisma/node_modules/@prisma/client/runtime/index.js:49652:12)
    at async PrismaClient._request (/Users/aya-eiya/Work/prisma/node_modules/@prisma/client/runtime/index.js:50572:18)
    at async Promise.all (index 0)
    at async main (/Users/aya-eiya/Work/prisma/src/main.js:6:3)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:45257) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:45257) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

An operation failed because it depends on one or more records that were required but not found. Record to update not found.

is never happen on prisma.user.updateMany. the actual error line is prisma.user.update.

this makes investigating difficult and causes confusion. so I think this must be a bug of $trancation.

Expected behavior

It must point out an actual error line.

Prisma information

Environment & setup

node: v14.17.0
OS: macOS 12.4 (21F79)
Kernel: Darwin Kernel Version 21.5.0: Tue Apr 26 21:08:29 PDT 2022; root:xnu-8020.121.3~4/RELEASE_ARM64_T8101

Prisma Version

"@prisma/client": "^4.0.0",
"prisma": "^4.0.0"
@aya-eiya aya-eiya added the kind/bug A reported bug. label Jul 19, 2022
@aqrln aqrln added team/client Issue for team Client. bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. labels Jul 19, 2022
@puncleV
Copy link

puncleV commented Jul 22, 2022

Reproduced with ^3.15.2 version. All errors in array of queries for $transaction being printed as an error within the first query call.

@garrensmith garrensmith added topic: $transaction Related to .$transaction(...) Client API topic: transaction tech/typescript Issue for tech TypeScript. process/candidate labels Jul 28, 2022
@SevInf SevInf self-assigned this Oct 17, 2022
SevInf added a commit that referenced this issue Oct 17, 2022
@SevInf
Copy link
Contributor

SevInf commented Oct 17, 2022

Reproduction

@SevInf SevInf added bug/2-confirmed Bug has been reproduced and confirmed. and removed bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. labels Nov 9, 2022
SevInf added a commit to prisma/prisma-engines that referenced this issue Nov 11, 2022
Adds `batch_request_idx` property to user facing errors. On the client,
that would allow us to build correct error message for `$transaction`
errors.

Ref: prisma/prisma#15433, prisma/prisma#14373
SevInf added a commit to prisma/prisma-engines that referenced this issue Nov 11, 2022
Adds `batch_request_idx` property to user facing errors. On the client,
that would allow us to build correct error message for `$transaction`
errors.

Ref: prisma/prisma#15433, prisma/prisma#14373
SevInf added a commit that referenced this issue Nov 11, 2022
Engine PR: prisma/prisma-engines#3384

Uses newly added `batch_request_idx` property of an errors to identify
and correctly report error location within a batch.

Fix #15433
Fix #14373
SevInf added a commit to prisma/prisma-engines that referenced this issue Nov 11, 2022
Adds `batch_request_idx` property to user facing errors. On the client,
that would allow us to build correct error message for `$transaction`
errors.

Ref: prisma/prisma#15433, prisma/prisma#14373
SevInf added a commit that referenced this issue Nov 11, 2022
Engine PR: prisma/prisma-engines#3384

Uses newly added `batch_request_idx` property of an errors to identify
and correctly report error location within a batch.

Fix #15433
Fix #14373
SevInf added a commit that referenced this issue Nov 11, 2022
Engine PR: prisma/prisma-engines#3384

Uses newly added `batch_request_idx` property of an errors to identify
and correctly report error location within a batch.

Fix #15433
Fix #14373
SevInf added a commit that referenced this issue Nov 14, 2022
Engine PR: prisma/prisma-engines#3384

Uses newly added `batch_request_idx` property of an errors to identify
and correctly report error location within a batch.

Fix #15433
Fix #14373
SevInf added a commit to prisma/prisma-engines that referenced this issue Nov 15, 2022
* qe: Identify which request in a batch caused error

Adds `batch_request_idx` property to user facing errors. On the client,
that would allow us to build correct error message for `$transaction`
errors.

Ref: prisma/prisma#15433, prisma/prisma#14373
SevInf added a commit that referenced this issue Nov 15, 2022
Engine PR: prisma/prisma-engines#3384

Uses newly added `batch_request_idx` property of an errors to identify
and correctly report error location within a batch.

Fix #15433
Fix #14373
SevInf added a commit that referenced this issue Nov 15, 2022
Engine PR: prisma/prisma-engines#3384

Uses newly added `batch_request_idx` property of an errors to identify
and correctly report error location within a batch.

Fix #15433
Fix #14373
SevInf added a commit that referenced this issue Nov 16, 2022
Engine PR: prisma/prisma-engines#3384

Uses newly added `batch_request_idx` property of an errors to identify
and correctly report error location within a batch.

Fix #15433
Fix #14373
SevInf added a commit that referenced this issue Nov 16, 2022
Engine PR: prisma/prisma-engines#3384

Uses newly added `batch_request_idx` property of an errors to identify
and correctly report error location within a batch.

Fix #15433
Fix #14373
SevInf added a commit that referenced this issue Nov 17, 2022
Engine PR: prisma/prisma-engines#3384

Uses newly added `batch_request_idx` property of an errors to identify
and correctly report error location within a batch.

Fix #15433
Fix #14373
SevInf added a commit that referenced this issue Nov 17, 2022
…6240)

Engine PR: prisma/prisma-engines#3384

Uses newly added `batch_request_idx` property of an errors to identify
and correctly report error location within a batch.

Fix #15433
Fix #14373
@janpio janpio added this to the 4.7.0 milestone Nov 17, 2022
jkomyno pushed a commit that referenced this issue Dec 21, 2022
…6240)

Engine PR: prisma/prisma-engines#3384

Uses newly added `batch_request_idx` property of an errors to identify
and correctly report error location within a batch.

Fix #15433
Fix #14373
jkomyno pushed a commit that referenced this issue Dec 21, 2022
…6240)

Engine PR: prisma/prisma-engines#3384

Uses newly added `batch_request_idx` property of an errors to identify
and correctly report error location within a batch.

Fix #15433
Fix #14373
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. tech/typescript Issue for tech TypeScript. topic: $transaction Related to .$transaction(...) Client API topic: transaction
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants