paljs / prisma-tools

Prisma tools to help you generate CRUD system for GraphQL servers
https://paljs.com
MIT License
683 stars 54 forks source link

Panic error on deleting #183

Closed CarloAndreoli1994 closed 3 years ago

CarloAndreoli1994 commented 3 years ago

There seems to be a problem when trying to delete entity with multiple relations with other tables. It throws a Panic error

Here's the interested Prisma schema:

model Attachment {
  id             Int      @id @default(autoincrement())
  type           String
  title          String?
  path           String?
  thumbnails     String?
  public         Boolean? @default(true)
  extRef         String?
  News           News[]
}

model Group {
  id             Int    @id @default(autoincrement())
  name           String
  News           News[]
}

model News {
  id                       Int            @id @default(autoincrement())
  published                Boolean        @default(false)
  accessType               String
  creationDate             DateTime       @default(now())
  publishedDate            DateTime       @default(now())
  expiryDate               String?
  /// @onDelete(CASCADE)
  Attachment               Attachment[]
  /// @onDelete(CASCADE)
  Group                    Group[]
  /// @onDelete(CASCADE)
  NewsCategory             NewsCategory[]
}

model NewsCategory {
  id                 Int                @id @default(autoincrement())
  iconName           String?
  color              String?
  parentId           Int?
  NewsCategory       NewsCategory?      @relation("NewsCategoryToNewsCategory_parentId", fields: [parentId], references: [id])
  /// @onDelete(CASCADE)
  other_NewsCategory NewsCategory[]     @relation("NewsCategoryToNewsCategory_parentId")
  /// @onDelete(CASCADE)
  News               News[]

  @@index([parentId], name: "parentId")
}

And this is the command used for deleting News entity:

  public async deleteNewsMulti(newsIds: number[]) {
    await this._prismaDelete.onDelete({ model: 'news', where: { id: { in: newsIds } }, deleteParent: true });
    return;
  }

The error is the following:

error:   🔥 error: PrismaClientUnknownRequestError2 [PrismaClientUnknownRequestError]: 
Invalid `prisma.news.findMany()` invocation:

  PANIC in query-engine/core/src/interpreter/query_interpreters/nested_read.rs:78:56
1

This is a non-recoverable error which probably happens when the Prisma Query Engine has a panic.

If you want the Prisma team to look into it, please open the link above 🙏
To increase the chance of success, please post your schema and a snippet of
how you used Prisma Client in the issue. 

    at PrismaClientFetcher.request (/Users/ultrastark/Documents/megaphone-api-v2_01/node_modules/@prisma/client/runtime/index.js:78134:15)
    at processTicksAndRejections (internal/process/task_queues.js:97:5) {
  [stack]: 'Error: \n' +
    'Invalid `prisma.news.findMany()` invocation:\n' +
    '\n' +
    '\n' +
    '  PANIC in query-engine/core/src/interpreter/query_interpreters/nested_read.rs:78:56\n' +
    '1\n' +
    '\n' +
    'This is a non-recoverable error which probably happens when the Prisma Query Engine has a panic.\n'

The entities are correctly deleted if trying to delete them individually.

Thanks.

AhmedElywa commented 3 years ago

our plugin not working with many to many relations