Skip to content

Error on table update using a mapped field in where clause #2329

@icomad

Description

@icomad

Bug description

Hi, I'm on 2.0.0-alpha.1174 and I get an error when trying to update a table using a mapped field in the where clause

How to reproduce

The relevant portion of my prisma schema:

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

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

model FriendRequest {
  createdAt        DateTime   @default(now()) @map(name: "created_at")
  toUserId         Int        @map(name: "to_user_id")
  status           ReqStatus  @default(pending)
  fromUserId       Int        @map(name: "from_user_id")
  toUser           User       @relation("friend_requests_to", fields: [toUserId], references: [id])
  fromUser         User       @relation("friend_requests_from", fields: [fromUserId], references: [id])

  @@id([fromUserId, toUserId])
  @@map(name: "friend_requests")
}

The code to update the table:

await prisma.friendRequest.update({
    where: {
        fromUserId_toUserId: {fromUserId: 1, toUserId: 2}
    }, 
    data: {status: "accepted"}
});

Note: the hardcoded fromUserId: 1 and toUserId: 2 are present in the database

The above code does not work and throw this error:

UnhandledPromiseRejectionWarning: Error:
Invalid `prisma.friendRequest.update()` invocation in /path/to/the/code

followed by this one:

Error in Prisma Client:
PANIC: called `Option::unwrap()` on a `None` value in
query-engine/core/src/query_graph_builder/extractors/filters.rs:279:35

If i change the prisma schema to this:

model FriendRequest {
  createdAt        DateTime   @default(now()) @map(name: "created_at")
  to_user_id         Int       
  status           ReqStatus  @default(pending)
  from_user_id       Int        
  toUser           User       @relation("friend_requests_to", fields: [to_user_id], references: [id])
  fromUser         User       @relation("friend_requests_from", fields: [from_user_id], references: [id])

  @@id([from_user_id, to_user_id])
  @@map(name: "friend_requests")
}

and called npx @prisma/cli@alpha generate using this update call:

await prisma.friendRequest.update({
    where: {
        from_user_id_to_user_id: {from_user_id: 1, to_user_id: 2}
    }, 
    data: {status: "accepted"}
});

everything works fine

Expected behavior

I would expect the status field being updated in the database

Prisma information

Shared above

Environment & setup

  • OS: macOS 10.15.2
  • Database: PostgreSQL
  • Prisma version: 2.0.0-alpha.1174
  • Node.js version: 13.12.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug/2-confirmedBug has been reproduced and confirmed.kind/bugA reported bug.tech/enginesIssue for tech Engines.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions