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

Errors at nested writes #5012

Closed
vadim-shilov opened this issue Nov 19, 2019 · 6 comments
Closed

Errors at nested writes #5012

vadim-shilov opened this issue Nov 19, 2019 · 6 comments
Assignees
Labels
kind/improvement An improvement to existing feature and code. team/client Issue for team Client. topic: error
Milestone

Comments

@vadim-shilov
Copy link

Hello!

Don't you think that throwing an error in the following cases is not worth it?

  1. nested update of a non-existing record
Error: 
Invalid `photon.()` invocation in /home/vadim/Projects/Temp/index.js:11:36



Reason: AssertionError("Expected a valid parent ID to be present for nested update to-one case.")

    at PhotonFetcher.<anonymous> (/home/vadim/Projects/Temp/node_modules/@generated/photon/index.js:54:27)
    at Generator.throw (<anonymous>)
    at rejected (/home/vadim/Projects/Temp/node_modules/@generated/photon/index.js:6:65)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
  1. disconnection/nested deletion of a non-existing record
Error: 
Invalid `photon.()` invocation in /home/vadim/Projects/Temp/index.js:11:36



Reason: RecordsNotConnected { relation_name: "PostToUser", parent_name: "User", child_name: "Post" }

    at PhotonFetcher.<anonymous> (/home/vadim/Projects/Temp/node_modules/@generated/photon/index.js:54:27)
    at Generator.throw (<anonymous>)
    at rejected (/home/vadim/Projects/Temp/node_modules/@generated/photon/index.js:6:65)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
@pantharshit00
Copy link
Contributor

I think this behaviour is expected. We just need to return better errors which will happen once error spec is implemented(https://github.com/prisma/specs/tree/master/errors)

@vadim-shilov
Copy link
Author

Perhaps, in these cases, is no need to throw errors?
Maybe I'm wrong, but In my opinion, when rec is not connected the 'disconnect' action should complete successfully.
Regarding 'update' and 'delete' actions, I am of the same opinion.

@Jolg42
Copy link
Member

Jolg42 commented Sep 4, 2020

I could reproduce

  engine Engine Version query-engine 6a8054bb549e4cc23f157b0010cb2e95cb2637fb +0ms
  engine {
  engine   error: PrismaClientKnownRequestError: Query interpretation error. Error for binding '1': AssertionError("Expected a valid parent ID to be present for nested update to-one case.")
  engine       at NodeEngine.graphQLToJSError (/Users/j42/Dev/prisma/src/packages/client/src/__tests__/runtime-tests/blog-update/node_modules/@prisma/client/runtime/index.js:1:128787)
  prisma-client Prisma Client call: +94ms
  prisma-client prisma.user.update({
  prisma-client   where: {
  prisma-client     id: '576eddf9-2434-421f-9a86-58bede16fd95'
  prisma-client   },
  prisma-client   data: {
  prisma-client     name: null,
  prisma-client     profile: {
  prisma-client       update: {
  prisma-client         notrequired: null
  prisma-client       }
  prisma-client     }
  prisma-client   }
  prisma-client }) +1ms
  prisma-client Generated request: +0ms
  prisma-client mutation {
  prisma-client   updateOneUser(
  prisma-client     where: {
  prisma-client       id: "576eddf9-2434-421f-9a86-58bede16fd95"
  prisma-client     }
  prisma-client     data: {
  prisma-client       name: {
  prisma-client         set: null
  prisma-client       }
  prisma-client       profile: {
  prisma-client         update: {
  prisma-client           notrequired: {
  prisma-client             set: null
  prisma-client           }
  prisma-client         }
  prisma-client       }
  prisma-client     }
  prisma-client   ) {
  prisma-client     id
  prisma-client     email
  prisma-client     name
  prisma-client   }
  prisma-client }

schema

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

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

// / User model comment
model User {
  id    String  @default(uuid()) @id
  email String  @unique
  // / name comment
  name  String?
  posts Post[]
  profile Profile?
}

model Profile {
  id     String     @default(cuid()) @id
  bio    String?
  notrequired String?
  user   User    @relation(fields: [userId], references: [id])
  userId String     @unique
}

model Post {
  id        String   @default(cuid()) @id
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
  published Boolean
  title     String
  content   String?
  optionnal String?
  authorId  String? @map("author")
  author    User?    @relation(fields: [authorId], references: [id])
}

@Jolg42
Copy link
Member

Jolg42 commented Sep 4, 2020

Here what happened is that I had one User without a Profile and I was trying to update the Profile, which is not possible because it didn't exist (needs to be created first).

@pantharshit00 pantharshit00 transferred this issue from prisma/prisma-client-js Jan 13, 2021
@pantharshit00 pantharshit00 added kind/improvement An improvement to existing feature and code. topic: error team/client Issue for team Client. labels Jan 13, 2021
@timsuchanek
Copy link
Contributor

Related to #5015

@matthewmueller matthewmueller added this to the 2.18.0 milestone Feb 17, 2021
@matthewmueller
Copy link
Contributor

matthewmueller commented Feb 24, 2021

For nested update of a non-existing record, we're tracking that in #5015

For disconnection/nested deletion of a non-existing record, I think the error is better now:

PrismaClientKnownRequestError2 [PrismaClientKnownRequestError]: 
Invalid `prisma.user.update()` invocation:


  The records for relation `PostToUser` between the `User` and `Post` models are not connected.
    at cb (/Users/m/dev/src/github.com/prisma/qa-errors/node_modules/@prisma/client/runtime/index.js:78689:17)
    at processTicksAndRejections (internal/process/task_queues.js:97:5) {
  code: 'P2017',
  clientVersion: '2.17.0',
  meta: {
    relation_name: 'PostToUser',
    parent_name: 'User',
    child_name: 'Post'
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/improvement An improvement to existing feature and code. team/client Issue for team Client. topic: error
Projects
None yet
Development

No branches or pull requests

5 participants