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

Bug: Upsert with @@unique should never fail #18984

Closed
Untel opened this issue Apr 27, 2023 · 2 comments
Closed

Bug: Upsert with @@unique should never fail #18984

Untel opened this issue Apr 27, 2023 · 2 comments
Labels
kind/bug A reported bug.

Comments

@Untel
Copy link

Untel commented Apr 27, 2023

Bug description

Hi !

I have this error
Unique constraint failed on the fields: (`challengeId`,`userId`)
When using a unique contraint in the where of upsert
By logic, this error should never happen as it's an upsert, it should trigger the update condition, and never add a new row.

Am i missing something ?

How to reproduce

Copy/Past the prisma information in a new project

Expected behavior

No response

Prisma information

model Participation {
  id                String @id @default(cuid())
  challengeId       String
  userId            String
  challenge         Challenge @relation(fields: [challengeId], references: [id])
  user              User @relation(fields: [userId], references: [id])
  createdAt         DateTime @default(now())
  // other stuff
  @@unique([challengeId, userId])
}
prisma.participation.upsert({
  where: {
    challengeId_userId: {
      challengeId: challengeId,
      userId: userId,
    },
  },
  update: {
    // do stuff
  },
  create: {
    user: {
      connect: {
        id: userId,
      },
    },
    challenge: {
      connect: {
        id: challengeId,
      },
    },
    // do stuff
  },
});

Environment & setup

  • OS: macOS
  • Database: PostgreSQL
  • Node.js version: 19.9

Prisma Version

4.10.0

I also tried with 4.5.0-dev.38 following this thread

@Untel Untel added the kind/bug A reported bug. label Apr 27, 2023
@Untel
Copy link
Author

Untel commented Apr 27, 2023

Well nevermind, it was an asynchronous problem.
I was doing many request in parallel.

@Untel Untel closed this as completed Apr 27, 2023
@sxppyyy
Copy link

sxppyyy commented Jan 22, 2024

Well nevermind, it was an asynchronous problem. I was doing many request in parallel.

How do u fixed that error (Unique constraint failed on the fields)?

I have the same error when I try to create about 2 users asynchronously

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug A reported bug.
Projects
None yet
Development

No branches or pull requests

2 participants