question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Panic on querying a model with a m-n relation to another model and selecting just the ids

See original GitHub issue

Hi Prisma Team! My Prisma Client just crashed. This is the report:

My team and I just upgraded from v2.8.0 to v2.10 directly

Versions

Name Version
Node v14.3.0
OS darwin
Prisma Client 2.10.0

Logs

C%0A++++++previewFeatures%3A+%5BArray%5D%2C%0A++++++config%3A+%7B%7D%0A++++%7D%2C%0A++++showColors%3A+false%2C%0A++++logLevel%3A+undefined%2C%0A++++logQueries%3A+undefined%2C%0A++++flags%3A+%5B%5D%2C%0A++++clientVersion%3A+%272.10.0%27%2C%0A++++enableExperimental%3A+%5B+%27transaction%27%2C+%27atomicNumberOperations%27+%5D%2C%0A++++useUds%3A+undefined%0A++%7D%0A%7D%0Aprisma-client+%7B%0A++engineConfig%3A+%7B%0A++++cwd%3A+%27%2FUsers%2Fpakatagoh%2FDocuments%2Fhackwagon-v2%2Fgql%27%2C%0A++++enableDebugLogs%3A+false%2C%0A++++enableEngineDebugMode%3A+undefined%2C%0A++++datamodelPath%3A+%27%2FUsers%2Fpakatagoh%2FDocuments%2Fhackwagon-v2%2Fnode_modules%2F.prisma%2Fclient%2Fschema.prisma%27%2C%0A++++prismaPath%3A+undefined%2C%0A++++engineEndpoint%3A+undefined%2C%0A++++generator%3A+%7B%0A++++++name%3A+%27client%27%2C%0A++++++provider%3A+%27prisma-client-js%27%2C%0A++++++output%3A+%27%2FUsers%2Fpakatagoh%2FDocuments%2Fhackwagon-v2%2Fnode_modules%2F%40prisma%2Fclient%27%2C%0A++++++binaryTargets%3A+%5B%5D%2C%0A++++++previewFeatures%3A+%5BArray%5D%2C%0A++++++config%3A+%7B%7D%0A++++%7D%2C%0A++++showColors%3A+false%2C%0A++++logLevel%3A+undefined%2C%0A++++logQueries%3A+undefined%2C%0A++++flags%3A+%5B%5D%2C%0A++++clientVersion%3A+%272.10.0%27%2C%0A++++enableExperimental%3A+%5B+%27transaction%27%2C+%27atomicNumberOperations%27+%5D%2C%0A++++useUds%3A+undefined%0A++%7D%0A%7D%0AplusX+Execution+permissions+of+%2FUsers%2Fpakatagoh%2FDocuments%2Fhackwagon-v2%2Fnode_modules%2F.prisma%2Fclient%2Fquery-engine-darwin+are+fine%0AplusX+Execution+permissions+of+%2FUsers%2Fpakatagoh%2FDocuments%2Fhackwagon-v2%2Fnode_modules%2F.prisma%2Fclient%2Fquery-engine-darwin+are+fine%0Aprisma-client+Error%3A+PANIC%3A+1%0A%0AThis+is+a+non-recoverable+error+which+probably+happens+when+the+Prisma+Query+Engine+has+a+panic.%0A%0Ahttps%3A%2F%2Fgithub.com%2Fprisma%2Fprisma-client-js%2Fissues%2Fnew%3Fbody%3DHi%2BPrisma%2BTeam%2521%2BMy%2BPrisma%2BClient%2Bjust%2Bcrashed.%2BThis%2Bis%2Bthe%2Breport%253A%250A%2523%2523%2BVersions%250A%250A%257C%2BName%2B%2B%2B%2B%2B%2B%2B%2B%2B%2B%2B%2B%257C%2BVersion%2B%2B%2B%2B%2B%2B%2B%2B%2B%2B%2B%2B%257C%250A%257C-----------------%257C--------------------%257C%250A%257C%2BNode%2B%2B%2B%2B%2B%2B%2B%2B%2B%2B%2B%2B%257C%2Bv14.3.0%2B%2B%2B%2B%2B%2B%2B%2B%2B%2B%2B%2B%257C%2B%250A%257C%2BOS%2B%2B%2B%2B%2B%2B%2B%2B%2B%2B%2B%2B%2B%2B%257C%2Bdarwin%2B%2B%2B%2B%2B%2B%2B%2B%2B%2B%2B%2B%2B%257C%250A%257C%2BPrisma%2BClient%2B%2B%2B%257C%2B2.10.0%2B%2B%2B%2B%2B%2B%2B%2B%2B%2B%2B%2B%2B%257C%250A%250A%250A%250A%2523%2523%2BLogs%250A%2560%2560%2560%250Aprisma-client%2B%257B%250A%2B%2BengineConfig%253A%2B%257B%250A%2B%2B%2B%2Bcwd%253A%2B%2527%252FUsers%252Fpakatagoh%252FDocuments%252Fhackwagon-v2%252Fgql%2527%252C%250A%2B%2B%2B%2BenableDebugLogs%253A%2Bfalse%252C%250A%2B%2B%2B%2BenableEngineDebugMode%253A%2Bundefined%252C%250A%2B%2B%2B%2BdatamodelPath%253A%2B%2527%252FUsers%252Fpakatagoh%252FDocuments%252Fhackwagon-v2%252Fnode_modules%252F.prisma%252Fclient%252Fschema.prisma%2527%252C%250A%2B%2B%2B%2BprismaPath%253A%2Bundefined%252C%250A%2B%2B%2B%2BengineEndpoint%253A%2Bundefined%252C%250A%2B%2B%2B%2Bgenerator%253A%2B%257B%250A%2B%2B%2B%2B%2B%2Bname%253A%2B%2527client%2527%252C%250A%2B%2B%2B%2B%2B%2Bprovider%253A%2B%2527prisma-client-js%2527%252C%250A%2B%2B%2B%2B%2B%2Boutput%253A%2B%2527%252FUsers%252Fpakatagoh%252FDocuments%252Fhackwagon-v2%252Fnode_modules%252F%2540prisma%252Fclient%2527%252C%250A%2B%2B%2B%2B%2B%2BbinaryTargets%253A%2B%255B%255D%252C%250A%2B%2B%2B%2B%2B%2BpreviewFeatures%253A%2B%255BArray%255D%252C%250A%2B%2B%2B%2B%2B%2Bconfig%253A%2B%257B%257D%250A%2B%2B%2B%2B%257D%252C%250A%2B%2B%2B%2BshowColors%253A%2Bfalse%252C%250A%2B%2B%2B%2BlogLevel%253A%2Bundefined%252C%250A%2B%2B%2B%2BlogQueries%253A%2Bundefined%252C%250A%2B%2B%2B%2Bflags%253A%2B%255B%255D%252C%250A%2B%2B%2B%2BclientVersion%253A%2B%25272.10.0%2527%252C%250A%2B%2B%2B%2BenableExperimental%253A%2B%255B%2B%2527transaction%2527%252C%2B%2527atomicNumberOperations%2527%2B%255D%252C%250A%2B%2B%2B%2BuseUds%253A%2Bundefined%250A%2B%2B%257D%250A%257D%250Aprisma-client%2B%257B%250A%2B%2BengineConfig%253A%2B%257B%250A%2B%2B%2B%2Bcwd%253A%2B%2527%252FUsers%252Fpakatagoh%252FDocuments%252Fhackwagon-v2%252Fgql%2527%252C%250A%2B%2B%2B%2BenableDebugLogs%253A%2Bfalse%252C%250A%2B%2B%2B%2BenableEngineDebugMode%253A%2Bundefined%252C%250A%2B%2B%2B%2BdatamodelPath%253A%2B%2527%252FUsers%252Fpakatagoh%252FDocuments%252Fhackwagon-v2%252Fnode_modules%252F.prisma%252Fclient%252Fschema.prisma%2527%252C%250A%2B%2B%2B%2BprismaPath%253A%2Bundefined%252C%250A%2B%2B%2B%2BengineEndpoint%253A%2Bundefined%252C%250A%2B%2B%2B%2Bgenerator%253A%2B%257B%250A%2B%2B%2B%2B%2B%2Bname%253A%2B%2527client%2527%252C%250A%2B%2B%2B%2B%2B%2Bprovider%253A%2B%2527prisma-client-js%2527%252C%250A%2B%2B%2B%2B%2B%2Boutput%253A%2B%2527%252FUsers%252Fpakatagoh%252FDocuments%252Fhackwagon-v2%252Fnode_modules%252F%2540prisma%252Fclient%2527%252C%250A%2B%2B%2B%2B%2B%2BbinaryTargets%253A%2B%255B%255D%252C%250A%2B%2B%2B%2B%2B%2BpreviewFeatures%253A%2B%255BArray%255D%252C%250A%2B%2B%2B%2B%2B%2Bconfig%253A%2B%257B%257D%250A%2B%2B%2B%2B%257D%252C%250A%2B%2B%2B%2BshowColors%253A%2Bfalse%252C%250A%2B%2B%2B%2BlogLevel%253A%2Bundefined%252C%250A%2B%2B%2B%2BlogQueries%253A%2Bundefined%252C%250A%2B%2B%2B%2Bflags%253A%2B%255B%255D%252C%250A%2B%2B%2B%2BclientVersion%253A%2B%25272.10.0%2527%252C%250A%2B%2B%2B%2BenableExperimental%253A%2B%255B%2B%2527transaction%2527%252C%2B%2527atomicNumberOperations%2527%2B%255D%252C%250A%2B%2B%2B%2BuseUds%253A%2Bundefined%250A%2B%2B%257D%250A%257D%250AplusX%2BExecution%2Bpermissions%2Bof%2B%252FUsers%252Fpakatagoh%252FDocuments%252Fhackwagon-v2%252Fnode_modules%252F.prisma%252Fclient%252Fquery-engine-darwin%2Bare%2Bfine%250AplusX%2BExecution%2Bpermissions%2Bof%2B%252FUsers%252Fpakatagoh%252FDocuments%252Fhackwagon-v2%252Fnode_modules%252F.prisma%252Fclient%252Fquery-engine-darwin%2Bare%2Bfine%250A%2560%2560%2560%26title%3DPANIC%253A%2B1%26template%3Dbug_report.md%0A%0AIf+you+want+the+Prisma+team+to+look+into+it%2C+please+open+the+link+above+%F0%9F%99%8F%0A%0A++++at+NodeEngine3.handleRequestError+%28%2FUsers%2Fpakatagoh%2FDocuments%2Fhackwagon-v2%2Fnode_modules%2F%40prisma%2Fclient%2Fruntime%2Findex.js%3A9073%3A21%29%0A++++at+%2FUsers%2Fpakatagoh%2FDocuments%2Fhackwagon-v2%2Fnode_modules%2F%40prisma%2Fclient%2Fruntime%2Findex.js%3A9724%3A36%0A++++at+processTicksAndRejections+%28internal%2Fprocess%2Ftask_queues.js%3A97%3A5%29%0A++++at+async+PrismaClientFetcher.request+%28%2FUsers%2Fpakatagoh%2FDocuments%2Fhackwagon-v2%2Fnode_modules%2F%40prisma%2Fclient%2Fruntime%2Findex.js%3A15748%3A24%29%0A%60%60%60&title=PANIC%3A+1&template=bug_report.md

If+you+want+the+Prisma+team+to+look+into+it,+please+open+the+link+above+🙏

++++at+NodeEngine3.handleRequestError+(/Users/pakatagoh/Documents/hackwagon-v2/node_modules/@prisma/client/runtime/index.js:9073:21)
++++at+/Users/pakatagoh/Documents/hackwagon-v2/node_modules/@prisma/client/runtime/index.js:9724:36
++++at+processTicksAndRejections+(internal/process/task_queues.js:97:5)
++++at+async+PrismaClientFetcher.request+(/Users/pakatagoh/Documents/hackwagon-v2/node_modules/@prisma/client/runtime/index.js:15748:24)
plusX+Execution+permissions+of+/Users/pakatagoh/Documents/hackwagon-v2/node_modules/.prisma/client/query-engine-darwin+are+fine
plusX+Execution+permissions+of+/Users/pakatagoh/Documents/hackwagon-v2/node_modules/.prisma/client/query-engine-darwin+are+fine
```&title=PANIC:+1&template=bug_report.md

in our schema.prisma, there’s a m-n relationship between CheckListTask and CheckListTaskDocument

model CheckListTask {
  id                     String                  @id @default(cuid())
  name                   String
  desc                   String?
  content                String?
  isCompleted            Boolean?                @default(false)
  isCompletedByUserId    String?                 @map("isCompletedBy")
  isCompletedBy          User?                   @relation(fields: [isCompletedByUserId], references: [id])
  isCompletedAt          DateTime?
  dueByLessonNum         Int?
  checkListTaskDocuments CheckListTaskDocument[]
  createdAt              DateTime                @default(now())
  updatedAt              DateTime                @updatedAt
  checkListSection       CheckListSection?       @relation(fields: [checkListSectionId], references: [id])
  checkListSectionId     String?                 @map("checkListSection")
}

model CheckListTaskDocument {
  id             String          @id @default(cuid())
  fileName       String
  extension      String?
  path           String?
  pipeFrom       String?
  createdAt      DateTime        @default(now())
  updatedAt      DateTime        @updatedAt
  checkListTasks CheckListTask[]
  uploadedById   String?         @map("uploadedBy")
  uploadedBy     User?           @relation(fields: [uploadedById], references: [id])
}

We are using graphql with a resolver that gets all the CheckListTaskDocuments which throws the panic error when we use select on CheckListTasks with just the id field

 async getAllChecklistTaskDocuments(_parent: any, _args: any, ctx: Context, info: any) {
    try {
      const foundChecklistTaskDocuments = await ctx.prisma2.checkListTaskDocument.findMany({
        where: {},
        include: {
          checkListTasks: {
            select: {
              id: true,
            },
          },
        },
      });

      return foundChecklistTaskDocuments;
    } catch (error) {
      console.error(error);
      throw new Error(error);
    }
  },

This also fails

  async getAllChecklistTaskDocuments(_parent: any, _args: any, ctx: Context, info: any) {
    try {
      const foundChecklistTaskDocuments = await ctx.prisma2.checkListTaskDocument.findMany({
        where: {},
        select: {
          id: true,
          checkListTasks: {
            select: {
              id: true,
            },
          },
          fileName: true,
          extension: true,
          path: true,
          pipeFrom: true,
          createdAt: true,
          updatedAt: true,
        },
      });

      return foundChecklistTaskDocuments;
    } catch (error) {
      console.error(error);
      throw new Error(error);
    }
  },

However we realized a few scenarios that works

  1. Using true as the value of checkListTasks seems to be working. See below
async getAllChecklistTaskDocuments(_parent: any, _args: any, ctx: Context, info: any) {
    try {
      const foundChecklistTaskDocuments = await ctx.prisma2.checkListTaskDocument.findMany({
        where: {},
        include: {
          checkListTasks: true,
        },
      });

      return foundChecklistTaskDocuments;
    } catch (error) {
      console.error(error);
      throw new Error(error);
    }
  },
  1. Selecting fields together with id in CheckListTasks will also do the trick and not cause a panic error. But of course, I do not need these other fields, I’m only interested in the id
  async getAllChecklistTaskDocuments(_parent: any, _args: any, ctx: Context, info: any) {
    try {
      const foundChecklistTaskDocuments = await ctx.prisma2.checkListTaskDocument.findMany({
        where: {},
        select: {
          id: true,
          checkListTasks: {
            select: {
              id: true,
              isCompleted: true,
              content: true,
              dueByLessonNum: true,
            },
          },
          fileName: true,
          extension: true,
          path: true,
          pipeFrom: true,
          createdAt: true,
          updatedAt: true,
        },
      });

      return foundChecklistTaskDocuments;
    } catch (error) {
      console.error(error);
      throw new Error(error);
    }
  },

Final thoughts

Is there an issue with my model? Or is there some issue with the mapping in prisma where if one selects just the id in a related model and not other fields, it’s not able to resolve? Given that the relation between 2 models is an m-n relation

Thanks!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
codethewebcommented, Feb 3, 2021

Can confirm that after moving from 2.16.0-dev.33 -> 2.16.0 it’s still working properly.

Thanks for the great work!

1reaction
strazicommented, Jan 6, 2021

Issue is still present in 2.14.0, and can still be fixed by adding an additional field to the id field.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to efficiently select only the IDs of a Belongs To Many ...
You want to eager load those ids on multiple models? · Yes, I want to do this with multiple models (collection) or a...
Read more >
Modeling and querying many-to-many relations - Prisma
Problem. Modeling and querying many-to-many relations in relational databases can be challenging. This article shows two examples how this can be approached ...
Read more >
Edges | ent
In relationship definition, the users edge is a M2M (many-to-many) relationship, and the groups edge is also a M2M (many-to-many) relationship.
Read more >
Many to many relation - PostgreSQL client and ORM for Go
Model (v).Insert() if err != nil { panic(err) } } // Select order and all items with following queries: // // SELECT "order"."id"...
Read more >
Relationships between tables in a Data Model
Add more power to your data analysis by creating relationships amogn different tables. A relationship is a connection between two tables that contain...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found