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: 1 -> Query can't return single id on Array field

See original GitHub issue

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

Versions

Name Version
Node v12.18.3
OS windows
Prisma Client 2.9.0

Logs

prisma-client {
  engineConfig: {
    cwd: '<project root>\\prisma',
    enableDebugLogs: false,
    enableEngineDebugMode: undefined,
    datamodelPath: '<project root>\\node_modules\\.prisma\\client\\schema.prisma',
    prismaPath: undefined,
    engineEndpoint: undefined,
    generator: {
      name: 'client',
      provider: 'prisma-client-js',
      output: '<project root>\\node_modules\\@prisma\\client',
      binaryTargets: [],
      previewFeatures: [],
      config: {}
    },
    showColors: false,
    logLevel: undefined,
    logQueries: undefined,
    flags: [],
    clientVersion: '2.9.0',
    enableExperimental: [],
    useUds: undefined
  }
}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
xmaxinex4commented, Oct 14, 2020

I realize the log above might not be enough information, so here is some context… I upgraded our project recently from prisma v 2.4.1 to 2.9.0. Before the upgrade, I was able to run these query:

query getSessions {
    sessions {
      id
      gradeLevels {
           id      
      }
    }
 }

query getGradeLevelInSchoolYears {
    gradeLevelInSchoolYears {
      id
      sessions {
           id      
      }
    }
  }

After the upgrade, I receive the Panic error posted above. I noticed that if I add a field to sessions or gradeLevels (example below) or if I just ask a single field that’s not the id on sessions or gradeLevels, the query runs without error

query getSessions {
    sessions {
      id
      gradeLevels {
           id    
           lastDayOfSchool  
      }
    }
 }

query getGradeLevelInSchoolYears {
    gradeLevelInSchoolYears {
      id
      sessions {
           id   
           endDate   
      }
    }
  }

The issue seems to be asking for a single id on a nested array field, although some other models with arrays fields can be queried for just the id successfully. Here is the schema for the two objects queried above:

model Session {
  id                        String                     @default(cuid()) @id
  dateCreated               DateTime?                  @default(now())
  dateUpdated               DateTime?                  @updatedAt
  sessionType               SessionType                @relation(fields: [sessionTypeId], references: [id])
  sessionTypeId             String
  sessionName               String
  beginDate                 DateTime
  endDate                   DateTime
  schoolYear                SchoolYear             @relation(fields: [schoolYearId], references: [id])
  schoolYearId              String
  gradingPeriods            GradingPeriod[]
  gradeLevels               GradeLevelInSchoolYear[]
}

model GradeLevelInSchoolYear {
  id                      String                 @default(cuid()) @id
  dateCreated             DateTime?              @default(now())
  dateUpdated             DateTime?              @updatedAt
  educationOrganization   EducationOrganization  @relation(fields: [educationOrganizationId], references: [id])
  educationOrganizationId String
  gradeLevel              GradeLevel             @relation(fields: [gradeLevelId], references: [id])
  gradeLevelId            String
  bellSchedules           BellSchedule[]
  scheduleConfiguration   ScheduleConfiguration? @relation(fields: [scheduleConfigurationId], references: [id])
  scheduleConfigurationId String?
  schoolYear              SchoolYear?            @relation(fields: [schoolYearId], references: [id])
  schoolYearId            String?
  schoolWeek              SchoolWeek?
  sessions                Session[]               @relation(references: [id])
  firstDayOfSchool        DateTime?
  lastDayOfSchool         DateTime?
  schoolCalendarEvents    SchoolYearCalendarEvent[] @relation(references: [id])
}
1reaction
xmaxinex4commented, Jan 8, 2021

Yes this is still an issue testing in version 2.14.0. I was able to reproduce the error using the basic quickstart starter project (https://www.prisma.io/docs/getting-started/quickstart-typescript) by making these changes:

schema.prisma:

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

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

model Post {
  id        Int     @id @default(autoincrement())
  title     String
  content   String?
  published Boolean @default(false)
  authors    User[]
}

model User {
  id    Int     @id @default(autoincrement())
  email String  @unique
  name  String?
  posts Post[]
}

script.ts:

import { PrismaClient } from '@prisma/client'

const prisma = new PrismaClient()

// A `main` function so that you can use async/await
async function main() {
  // This query passes without error because I added { title: true } to posts select
  // const usersPass = await prisma.user.findMany({
  //   select: { id: true, posts: { select: { id: true, title: true } } },
  // });

  // This query fails with error with just the id select on post
  const usersFail = await prisma.user.findMany({
    select: { id: true, posts: { select: { id: true } } },
  });

  // console.dir(usersPass, { depth: null });
  console.dir(usersFail, { depth: null });
}

main()
  .catch(e => {
    throw e
  })
  .finally(async () => {
    await prisma.$disconnect()
  })

I seeded the db with 3 users and 1 post that had 2 users and ran npm run dev Works on version 2.4.1, fails on 2.9.0 and latest 2.14.0

Using the starter project, I was able to see a more detailed error:

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

Versions

Name Version
Node v14.15.4
OS windows
Prisma Client 2.14.0
Query Engine query-engine 5d491261d382a2a5ffdc71de17072b0e409f1cc1
Database undefined

Query

query {
  findManyUser {
    id
    email
    posts {
      id
    }
  }
}

Logs

Repositories\\starter\\prisma' }  
  engine Search for Query Engine in C:\Users\maxin\Repositories\starter\node_modules\.prisma\client  
  engine port: undefined  
  engine { flags: [ '--enable-raw-queries' ] }  
  engine port: 56057  
  engine stdout  Starting a postgresql pool with 13 connections.  
  engine stdout  Started http server on http://127.0.0.1:56057  
  engine Search for Query Engine in C:\Users\maxin\Repositories\starter\node_modules\.prisma\client  
  engine stdout  PANIC in query-engine\core\src\interpreter\query_interpreters\nested_read.rs:78:56
1  
  engine TypeError: this.currentRequestPromise.cancel is not a function
  engine     at NodeEngine.handlePanic (C:\Users\maxin\Repositories\starter\node_modules\@prisma\client\runtime\index.js:26344:36)
  engine     at NodeEngine.setError (C:\Users\maxin\Repositories\starter\node_modules\@prisma\client\runtime\index.js:26290:16)
  engine     at LineStream.<anonymous> (C:\Users\maxin\Repositories\starter\node_modules\@prisma\client\runtime\index.js:26585:24)
  engine     at LineStream.emit (events.js:315:20)
  engine     at LineStream.EventEmitter.emit (domain.js:467:12)
  engine     at addChunk (internal/streams/readable.js:309:12)
  engine     at readableAddChunk (internal/streams/readable.js:284:9)
  engine     at LineStream.Readable.push (internal/streams/readable.js:223:10)
  engine     at LineStream.Transform.push (internal/streams/transform.js:166:32)
  engine     at LineStream._pushBuffer (C:\Users\maxin\Repositories\starter\node_modules\@prisma\client\runtime\index.js:23721:19)  {"timestamp":"Jan 07 21:17:38.326","level":"ERROR","fields":{"message":"PANIC","reason":"1","file":"query-engine\\core\\src\\interpreter\\query_interpreters\\nested_read.rs","line":78,"column":56},"target":"query_engine"}  
  engine {
  engine   error: Error: read ECONNRESET
  engine       at TCP.onStreamRead (internal/stream_base_commons.js:209:20) {
  engine     errno: -4077,
  engine     code: 'ECONNRESET',
  engine     syscall: 'read'
  engine   }
  engine }  
  engine {
  engine   error: Error: connect ECONNREFUSED 127.0.0.1:56057
  engine       at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16) {
  engine     errno: -4078,
  engine     code: 'ECONNREFUSED',
  engine     syscall: 'connect',
  engine     address: '127.0.0.1',
  engine     port: 56057
  engine   }
  engine }  
  engine There is a child that still runs and we want to start again  
  engine { cwd: 'C:\\Users\\maxin\\Repositories\\starter\\prisma' }  
  engine Search for Query Engine in C:\Users\maxin\Repositories\starter\node_modules\.prisma\client  
  engine { flags: [ '--enable-raw-queries' ] }  
  engine port: 56061  
  engine Client Version: 2.14.0  
  engine Engine Version: query-engine 5d491261d382a2a5ffdc71de17072b0e409f1cc1  
  engine Active provider: postgresql  
  engine stdout  Starting a postgresql pool with 13 connections.  
  engine stdout  Started http server on http://127.0.0.1:56061  
  engine Search for Query Engine in C:\Users\maxin\Repositories\starter\node_modules\.prisma\client  
  engine stdout  PANIC in query-engine\core\src\interpreter\query_interpreters\nested_read.rs:78:56
1  
  engine TypeError: this.currentRequestPromise.cancel is not a function
  engine     at NodeEngine.handlePanic (C:\Users\maxin\Repositories\starter\node_modules\@prisma\client\runtime\index.js:26344:36)
  engine     at NodeEngine.setError (C:\Users\maxin\Repositories\starter\node_modules\@prisma\client\runtime\index.js:26290:16)
  engine     at LineStream.<anonymous> (C:\Users\maxin\Repositories\starter\node_modules\@prisma\client\runtime\index.js:26585:24)
  engine     at LineStream.emit (events.js:315:20)
  engine     at LineStream.EventEmitter.emit (domain.js:467:12)
  engine     at addChunk (internal/streams/readable.js:309:12)
  engine     at readableAddChunk (internal/streams/readable.js:284:9)
  engine     at LineStream.Readable.push (internal/streams/readable.js:223:10)
  engine     at LineStream.Transform.push (internal/streams/transform.js:166:32)
  engine     at LineStream._pushBuffer (C:\Users\maxin\Repositories\starter\node_modules\@prisma\client\runtime\index.js:23721:19)  {"timestamp":"Jan 07 21:17:38.423","level":"ERROR","fields":{"message":"PANIC","reason":"1","file":"query-engine\\core\\src\\interpreter\\query_interpreters\\nested_read.rs","line":78,"column":56},"target":"query_engine"}  
  engine {
  engine   error: Error: read ECONNRESET
  engine       at TCP.onStreamRead (internal/stream_base_commons.js:209:20) {
  engine     errno: -4077,
  engine     code: 'ECONNRESET',
  engine     syscall: 'read'
  engine   }
  engine }  

Client Snippet

import { PrismaClient } from '@prisma/client'

const prisma = new PrismaClient()

// Set up database with `npm run prisma:migrate`
// Set up client with `npm run prisma:generate`
// Seed databsae with `npm run seed`
// Run `npm run dev`

// A `main` function so that you can use async/await
async function main() {
  // This query passes without error because I added { title: true } to posts select
  // const usersPass = await prisma.user.findMany({
  //   select: { id: true, posts: { select: { id: true, title: true } } },
  // });

  // This query fails with error with just the id select on post
  const usersFail = await prisma.user.findMany({
    select: { id: true, posts: { select: { id: true } } },
  });

  // console.dir(usersPass, { depth: null });
  console.dir(usersFail, { depth: null });
}

main()
  .catch(e => {
    throw e
  })
  .finally(async () => {
    await prisma.$disconnect()
  })

Schema

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

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

model Post {
  id        Int     @id @default(autoincrement())
  title     String
  content   String?
  published Boolean @default(false)
  authors    User[]
}

model User {
  id    Int     @id @default(autoincrement())
  email String  @unique
  name  String?
  posts Post[]
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

panic: json: cannot unmarshal array into Go value of type main ...
The application is unmarshalling a JSON array to a struct. Unmarshal to a slice: var data []interface{} err = json.Unmarshal(body, &data).
Read more >
selecting an array element, based on subelement value -> jq ...
jq '.DATA | select(.DOMAIN=="domain2")'. I get. jq: error: Cannot index array with string. How do I find/select the desired subelement?
Read more >
Retrieving Result Sets - Go database/sql tutorial
We're using db.Query() to send the query to the database. We check the error, as usual. · We defer rows.Close() . · We...
Read more >
The way I handled possible null values from database rows in ...
Few weeks ago, I was working on one of the web services of my project, where back-end has been developed using Go and...
Read more >
Gomega is a matcher
Eventually can be passed functions that return at least one value. ... Eventually(func(g Gomega) (Widget, error) { ids, err := client.FetchIDs() g.
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