prisma: Syntax error with delete

Bug description

Calling delete causes a syntax error

How to reproduce

await ctx.prisma.user.delete({
        where: { email_brandId: { email: uniqueEmail, brandId: 'habitat' } },
      });

Prisma information

model User {
  id       String  @default(cuid()) @id
  createdAt  DateTime    @default(now())
  updatedAt  DateTime @updatedAt
  email      String
  brandId    String
  firstname     String?
  lastname     String?
  phone   String?

...

  couponUse  CouponUse[]

  @@unique([email, brandId])
}

model Coupon {
  code        String @id
  createdAt   DateTime    @default(now())
  updatedAt   DateTime @updatedAt
  couponUse   CouponUse[]
}

model CouponUse {
  id          String  @default(cuid()) @id
  createdAt   DateTime    @default(now())
  updatedAt   DateTime @updatedAt
  couponCode  String
  coupon      Coupon @relation(fields: [couponCode], references: [code])
  userId      String
  user        User @relation(fields: [userId], references: [id])
}

Debug:

onsole.log src/services/UserService.db.spec.ts:244
    Deleting user user-service-email@test.com

  prisma-client Prisma Client call: +8ms
  prisma-client prisma.user.delete({
  prisma-client   where: {
  prisma-client     email_brandId: {
  prisma-client       email: 'user-service-email@test.com',
  prisma-client       brandId: 'habitat'
  prisma-client     }
  prisma-client   }
  prisma-client }) +0ms
  prisma-client Generated request: +0ms
  prisma-client mutation {
  prisma-client   deleteOneUser(where: {
  prisma-client     email_brandId: {
  prisma-client       email: "user-service-email@test.com"
  prisma-client       brandId: "habitat"
  prisma-client     }
  prisma-client   }) {
  prisma-client     id
  prisma-client     createdAt
  prisma-client     updatedAt
  prisma-client     email
  prisma-client     brandId
  prisma-client     firstname
  prisma-client     lastname
  prisma-client     phone

...

  prisma-client   }
  prisma-client }
  prisma-client  +0ms
  engine {
  engine   error: PrismaClientUnknownRequestError: Error occurred during query execution:
  engine   ConnectorError(ConnectorError { user_facing_error: None, kind: QueryError(Error { kind: Db, cause: Some(DbError { severity: "ERROR", parsed_severity: Some(Error), code: SqlState("42601"), message: "syntax error at or near \")\"", detail: None, hint: None, position: Some(Original(72)), where_: None, schema: None, table: None, column: None, datatype: None, constraint: None, file: Some("scan.l"), line: Some(1128), routine: Some("scanner_yyerror") }) }) })
  engine       at NodeEngine.graphQLToJSError (/Users/kenono/apps/habitat/packages/back-end/node_modules/@prisma/client/runtime/index.js:1:19002)
  engine       at /Users/kenono/apps/habitat/packages/back-end/node_modules/@prisma/client/runtime/index.js:1:16489
  engine       at processTicksAndRejections (internal/process/task_queues.js:97:5)
  engine       at Dataloader.loader (/Users/kenono/apps/habitat/packages/back-end/node_modules/@prisma/client/runtime/index.js:1:50798)
  engine } +541ms
  printStack callsite Error
    at Object.s [as User] (/Users/kenono/apps/habitat/packages/back-end/node_modules/@prisma/client/runtime/index.js:1:48702)
    at Object.n.<computed> [as delete] (/Users/kenono/apps/habitat/packages/back-end/node_modules/@prisma/client/runtime/index.js:1:50328)
    at Object.<anonymous> (/Users/kenono/apps/habitat/packages/back-end/src/services/UserService.db.spec.ts:289:35)
    at processTicksAndRejections (internal/process/task_queues.js:97:5) +0ms
  engine Stopping Prisma engine +15ms
  getos { platform: 'darwin', libssl: undefined } +3s
  engine Stopping Prisma engine +0ms
  getos { platform: 'darwin', libssl: undefined } +0ms

Environment & setup

kens-mbp:back-end kenono$ npx prisma -v
@prisma/cli          : 2.0.0-beta.1
Current platform     : darwin
Query Engine         : prisma 2accb9c7eacdc984874eaeb63377fe705dfd3203 (at /Users/kenono/apps/habitat/packages/back-end/node_modules/@prisma/cli/query-engine-darwin)
Migration Engine     : migration-engine-cli 2accb9c7eacdc984874eaeb63377fe705dfd3203 (at /Users/kenono/apps/habitat/packages/back-end/node_modules/@prisma/cli/migration-engine-darwin)
Introspection Engine : introspection-core 2accb9c7eacdc984874eaeb63377fe705dfd3203 (at /Users/kenono/apps/habitat/packages/back-end/node_modules/@prisma/cli/introspection-engine-darwin)

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 16 (10 by maintainers)

Most upvoted comments

The problem was resolved by changing the Answer model to: (previous version listed above)

model Answer {
  id          String   @default(cuid()) @id
  content     String
  question    Question
  userId      String
  author      User @relation (fields: [userId], references: [id])
  createdAt   DateTime @default(now())
  updatedAt   DateTime @updatedAt
}

I guess prisma could be improved by providing better diagnostic messages