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

Prisma update and delete with extendedWhereUnique work with MongoDB shared but not serverless tier #18888

Closed
Tracked by #19380
akevinge opened this issue Apr 23, 2023 · 5 comments
Assignees
Labels
bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. kind/bug A reported bug. team/client Issue for team Client. topic: extendedWhereUnique Preview Feature topic: mongodb atlas serverless topic: mongodb topic: serverless

Comments

@akevinge
Copy link

akevinge commented Apr 23, 2023

Node: v16.20.0
Prisma: v4.11, v4.12, v4.13 (issue occurs with all of these versions)
OS/Runtimes: MacOS, Manjaro, Vercel serverless runtime (issue occurs with all of these OS/Runtimes)
Database: MongoDB Atlas, serverless tier, v6.3

Schema file

Original: https://github.com/UTDNebula/planner/blob/develop/prisma/schema.prisma
Truncated:

generator client {
  provider = "prisma-client-js"
  previewFeatures = ["extendedWhereUnique"]
}

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

model Plan {
  id              String              @id @default(auto()) @map("_id") @db.ObjectId
  name            String
  createdAt       DateTime            @default(now()) @map("created_at")
  updatedAt       DateTime            @default(now()) @map("updated_at")
  semesters       Semester[]
  transferCredits String[]
  User            User?               @relation(fields: [userId], references: [id], onDelete: Cascade)
  userId          String?             @db.ObjectId
  startSemester   SemesterCode
  endSemester     SemesterCode
}


model Course {
  id         String    @id @default(auto()) @map("_id") @db.ObjectId
  code       String
  color      String    @default("")
  semester   Semester? @relation(fields: [semesterId], references: [id], onDelete: Cascade)
  semesterId String?   @db.ObjectId
  locked     Boolean   @default(false)
  prereqOverriden Boolean @default(false)
  
  @@unique([semesterId, code])
}

model Semester {
  id      String       @id @default(auto()) @map("_id") @db.ObjectId
  code    SemesterCode
  courses Course[]
  plan    Plan?        @relation(fields: [planId], references: [id], onDelete: Cascade)
  planId  String?      @db.ObjectId
  color   String       @default("")
  locked  Boolean      @default(false)
}

type SemesterCode {
  semester SemesterType
  year     Int
}

enum SemesterType {
  f
  s
  u
}

// Necessary for Next auth
model Account {
  id                String  @id @default(auto()) @map("_id") @db.ObjectId
  userId            String  @db.ObjectId
  type              String
  provider          String
  providerAccountId String
  refresh_token     String? // @db.Text
  access_token      String? // @db.Text
  expires_at        Int?
  token_type        String?
  scope             String?
  id_token          String? // @db.Text
  session_state     String?
  user              User    @relation(fields: [userId], references: [id], onDelete: Cascade)

  @@unique([provider, providerAccountId])
}

model Session {
  id           String   @id @default(auto()) @map("_id") @db.ObjectId
  sessionToken String   @unique
  userId       String   @db.ObjectId
  expires      DateTime
  user         User     @relation(fields: [userId], references: [id], onDelete: Cascade)
}

model User {
  id                      String    @id @default(auto()) @map("_id") @db.ObjectId
  email                   String?   @unique
  emailVerified           DateTime?
  onboardingComplete      Boolean   @default(false)
  seenHomeOnboardingModal Boolean   @default(false)
  seenPlanOnboardingModal Boolean   @default(false)
  credit                  Credit[]
  accounts                Account[]
  sessions                Session[]
  plans                   Plan[]
}

Reproduction

The following query

await prisma.course.update({
    where: {
      semester: { plan: { userId: "a-user-id" } },
      semesterId_code: {
        semesterId: oldSemesterId,
        code: courseName,
      },
    },
    data: {
      semesterId: newSemesterId,
    },
  });

Fails with this error:

prisma:error
Invalid `prisma.semester.update()` invocation:


An operation failed because it depends on one or more records that were required but not found. No 'Semester' record (needed to inline the relation on 'Course' record) was found for a nested create on one-to-many relation 'CourseToSemester'.
PrismaClientKnownRequestError:
Invalid `prisma.semester.update()` invocation:


An operation failed because it depends on one or more records that were required but not found. No 'Semester' record (needed to inline the relation on 'Course' record) was found for a nested create on one-to-many relation 'CourseToSemester'.

The error ONLY occurs when:

  • MongoDB's serverless tier (MongoDB v6.3) is used
  • More than 1 user account is created

It works perfectly fine on MongoDB's shared tier (MongoDB 6.0.5)

Related: #15837

@jkomyno jkomyno added topic: serverless team/client Issue for team Client. topic: mongodb atlas serverless bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. topic: extendedWhereUnique Preview Feature labels Apr 24, 2023
@jkomyno
Copy link
Contributor

jkomyno commented Apr 24, 2023

Hi, could you please share all the required info in our bug report issue template?
I.e., your Prisma version, Prisma schema, Node.js version, OS.

Thank you.

@jkomyno jkomyno added bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. and removed bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. labels Apr 24, 2023
@akevinge
Copy link
Author

Hi, could you please share all the required info in our bug report issue template? I.e., your Prisma version, Prisma schema, Node.js version, OS.

Thank you.

Hi Jkomyno. Updated!

@Jolg42 Jolg42 added bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. and removed bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. labels May 23, 2023
@Jolg42 Jolg42 assigned Jolg42 and Weakky and unassigned Jolg42 May 31, 2023
@Weakky
Copy link
Member

Weakky commented Jun 6, 2023

Hey @akevinge,

I think you've provided the wrong failing query as I'm not able to reproduce your issue. The share query snippet updates the course, but the error suggests that it's happening on prisma.semester.update().

Could you perhaps share that query?

Thank you!

@janpio janpio changed the title Prisma update and delete with "extendedWhereUnique" work with MongoDB shared but not serverless tier Prisma update and delete with extendedWhereUnique work with MongoDB shared but not serverless tier Jun 7, 2023
@Jolg42 Jolg42 added bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. and removed bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. labels Jun 14, 2023
@janpio
Copy link
Member

janpio commented Jul 5, 2023

Ping @akevinge

@jkomyno
Copy link
Contributor

jkomyno commented Jul 13, 2023

Hey @akevinge, I'm closing this issue for inactivity and because we couldn't reproduce it. Feel free to comment here again with the actual failing query and answers to the questions we've asked so we can address this problem. Thanks!

@jkomyno jkomyno closed this as completed Jul 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. kind/bug A reported bug. team/client Issue for team Client. topic: extendedWhereUnique Preview Feature topic: mongodb atlas serverless topic: mongodb topic: serverless
Projects
None yet
Development

No branches or pull requests

5 participants