Skip to content

PANIC in query-engine/core/src/query_graph_builder/read/utils.rs:52:85called Result::unwrap() on an Err value: FieldNotFound { name: "_count", model: "List" } #6543

Closed
prisma/prisma-engines
#1980

Description

@jxe

I got an error when I tried to use your new selectRelationCount feature.

Versions

Name Version
Node v14.16.0
OS darwin
Prisma Client 2.20.1
Query Engine query-engine 60ba6551f29b17d7d6ce479e5733c70d9c00860e
Database undefined Edit by @janpio: prisma:engine Active provider: postgresql

Query

query {
  findUniqueSpace(where: {
    id: 5
  }) {
    id
    createdAt
    updatedAt
    name
    about
    _count {
      stories
      lists
    }
    stories(where: {
      isPublic: true
    }) {
      id
      userId
      createdAt
      updatedAt
      text
      spaceId
      listId
      isPublic
      user {
        id
        name
        nick
        handle
        photoUrl
      }
      senses {
        id
        knownAs {
          valId
          senseId
          type
          createdAt
          pickCount
          skipCount
          val {
            id
            n
            adj
          }
        }
        teaser
        text
      }
    }
    lists(where: {
      unlisted: false
    }) {
      name
      uuid
      randosCanJoin
      isPracticeGroup
      _count {
        memberships
        stories
      }
    }
  }
}

Logs

ent/runtime/index.js:24152:10)
    at LineStream.Transform._read (internal/streams/transform.js:205:10)
    at LineStream.Transform._write (internal/streams/transform.js:193:12)
    at writeOrBuffer (internal/streams/writable.js:358:12)
    at LineStream.Writable.write (internal/streams/writable.js:303:10)
    at Socket.ondata (internal/streams/readable.js:719:22)
    at Socket.emit (events.js:315:20)  {"timestamp":"Apr 13 10:16:44.809","level":"ERROR","fields":{"message":"PANIC","reason":"called `Result::unwrap()` on an `Err` value: FieldNotFound { name: \"_count\", model: \"List\" }","file":"query-engine/core/src/query_graph_builder/read/utils.rs","line":52,"column":85},"target":"query_engine","span":{"name":"find_related"},"spans":[{"name":"execute_single_operation"},{"name":"build"},{"name":"build_internal"},{"name":"dispatch_build"},{"name":"find_unique"},{"name":"find_related"}]}
prisma:engine Client Version: 2.20.1
prisma:engine Engine Version: query-engine 60ba6551f29b17d7d6ce479e5733c70d9c00860e
prisma:engine Active provider: postgresql
prisma:engine {
  error: SocketError: other side closed
      at Socket.onSocketEnd (/Users/joeedelman/Dropbox/repos/warez/mvill/node_modules/@prisma/client/runtime/index.js:25293:24)
      at Socket.emit (events.js:327:22)
      at endReadableNT (internal/streams/readable.js:1327:12)
      at processTicksAndRejections (internal/process/task_queues.js:80:21) {
    code: 'UND_ERR_SOCKET'
  }
}
prisma:engine { cwd: '/Users/joeedelman/Dropbox/repos/warez/mvill/db' }
prisma:engine Search for Query Engine in /Users/joeedelman/Dropbox/repos/warez/mvill/node_modules/.prisma/client
plusX Execution permissions of /Users/joeedelman/Dropbox/repos/warez/mvill/node_modules/.prisma/client/query-engine-darwin are fine
prisma:engine {
  flags: [
    '--enable-experimental=selectRelationCount',
    '--enable-raw-queries',
    '--port',
    '52506'
  ]
}
prisma:engine stdout  Starting a postgresql pool with 5 connections.
prisma:engine stdout  Started http server on http://127.0.0.1:52506
prisma:engine Search for Query Engine in /Users/joeedelman/Dropbox/repos/warez/mvill/node_modules/.prisma/client
plusX Execution permissions of /Users/joeedelman/Dropbox/repos/warez/mvill/node_modules/.prisma/client/query-engine-darwin are fine
prisma:engine stdout  PANIC in query-engine/core/src/query_graph_builder/read/utils.rs:52:85
called `Result::unwrap()` on an `Err` value: FieldNotFound { name: "_count", model: "List" }
prisma:engine TypeError: this.currentRequestPromise.cancel is not a function
    at NodeEngine.handlePanic (/Users/joeedelman/Dropbox/repos/warez/mvill/node_modules/@prisma/client/runtime/index.js:27023:36)
    at NodeEngine.setError (/Users/joeedelman/Dropbox/repos/warez/mvill/node_modules/@prisma/client/runtime/index.js:26969:16)
    at LineStream.<anonymous> (/Users/joeedelman/Dropbox/repos/warez/mvill/node_modules/@prisma/client/runtime/index.js:27259:24)
    at LineStream.emit (events.js:315:20)
    at addChunk (internal/streams/readable.js:309:12)
    at readableAddChunk (internal/streams/readable.js:284:9)
    at LineStream.Readable.push (internal/streams/readable.js:223:10)
    at LineStream.Transform.push (internal/streams/transform.js:166:32)
    at LineStream._pushBuffer (/Users/joeedelman/Dropbox/repos/warez/mvill/node_modules/@prisma/client/runtime/index.js:24158:19)
    at LineStream._transform (/Users/joeedelman/Dropbox/repos/warez/mvill/node_modules/@prisma/client/runtime/index.js:24152:10)
    at LineStream.Transform._read (internal/streams/transform.js:205:10)
    at LineStream.Transform._write (internal/streams/transform.js:193:12)
    at writeOrBuffer (internal/streams/writable.js:358:12)
    at LineStream.Writable.write (internal/streams/writable.js:303:10)
    at Socket.ondata (internal/streams/readable.js:719:22)
    at Socket.emit (events.js:315:20)  {"timestamp":"Apr 13 10:16:44.955","level":"ERROR","fields":{"message":"PANIC","reason":"called `Result::unwrap()` on an `Err` value: FieldNotFound { name: \"_count\", model: \"List\" }","file":"query-engine/core/src/query_graph_builder/read/utils.rs","line":52,"column":85},"target":"query_engine","span":{"name":"find_related"},"spans":[{"name":"execute_single_operation"},{"name":"build"},{"name":"build_internal"},{"name":"dispatch_build"},{"name":"find_unique"},{"name":"find_related"}]}
prisma:engine {
  error: SocketError: other side closed
      at Socket.onSocketEnd (/Users/joeedelman/Dropbox/repos/warez/mvill/node_modules/@prisma/client/runtime/index.js:25293:24)
      at Socket.emit (events.js:327:22)
      at endReadableNT (internal/streams/readable.js:1327:12)
      at processTicksAndRejections (internal/process/task_queues.js:80:21) {
    code: 'UND_ERR_SOCKET'
  }
}

Client Snippet

await db.space.findUnique({
    where,
    include: {
      _count: {
        select: {
          stories: true,
          lists: true,
        },
      },
      stories: {
        where: {
          isPublic: true,
        },
        include: {
          user: SelectUser,
          senses: SelectSense,
        },
      },
      lists: {
        select: {
    name: true,
    uuid: true,
    randosCanJoin: true,
    isPracticeGroup: true,
    _count: {
      select: {
        memberships: true,
        stories: true,
      },
    },
  },
        where: {
          unlisted: false,
        },
      },
    },
  })

Schema

// PLEASE ADD YOUR SCHEMA HERE IF POSSIBLE

Activity

  1. added
    bug/0-unknown
    kind/bug
    topic: previewFeatures
    on Apr 13, 2021
  2. matthewmueller commented on Apr 14, 2021

    @matthewmueller
    Contributor

    Do you mind adding your prisma schema or a minimal repro? Thanks!

  3. subnomo commented on May 5, 2021

    @subnomo

    I have also been getting this error. It seems to happen when you try to use _count on nested include or selects.

    According to the docs, _count can only be used in a top-level include or select. However TypeScript doesn't complain when I try to use it in a nested way, Prisma just panics.

    At the very least I think the error message should be better, but I definitely have a use case for nested _count, and I wish it would work as expected.

  4. added
    bug/1-unconfirmed
    and removed
    bug/0-unknown
    on May 5, 2021
  5. self-assigned this
    on May 19, 2021
  6. added this to the 2.24.0 milestone on May 19, 2021
  7. added
    bug/2-confirmed
    and removed
    bug/1-unconfirmed
    on May 22, 2021
  8. janpio commented on May 22, 2021

    @janpio
    Contributor

    Multiple more reports with reproduction schemas and with newer versions, reproductions confirmed by @pantharshit00 in the follow duplicate issues: #7091 + #7151 + #7217

  9. 41y08h commented on May 22, 2021

    @41y08h

    I think this error occurs when anyone tries to count nested relations meaning that if someone has a condition similar to this -
    User table having subscribers as a field that an array (came from a relation) and the User table is related to Video table.
    When Video table is queried and we want to join User table and also count the subscribers field.

    Something like this -

    query {
      findUniqueVideo(where: {
        id: 5
      }) {
        id
        title
        description
        src
        thumbnail
        duration
        views
        uploadedAt
        channel {
          id
          name
          picture
          _count {
            subscribers
          }
        }
      }
    }
    

    Here is the respective schema -

    generator client {
      provider        = "prisma-client-js"
      previewFeatures = ["selectRelationCount"]
    }
    
    datasource db {
      provider = "postgresql"
      url      = env("DATABASE_URL")
    }
    
    enum Provider {
      GOOGLE
    }
    
    model User {
      id                Int             @id @default(autoincrement())
      name              String          @db.VarChar(255)
      email             String          @unique @db.VarChar(255)
      picture           String?
      provider          Provider
      providerAccountId String          @db.VarChar(100)
      comments          Comment[]
      videos            Video[]
      createdAt         DateTime        @default(now())
      commentRatings    CommentRating[]
      videoRatings      VideoRating[]
      subscribers       Subscriber[]    @relation("subscriber")
      subscriptions     Subscriber[]    @relation("channel")
    }
    
    model Video {
      id          Int           @id @default(autoincrement())
      title       String
      description String
      src         String
      thumbnail   String
      duration    Int
      userId      Int
      views       Int?          @default(0)
      channel     User?         @relation(fields: [userId], references: [id])
      comments    Comment[]
      uploadedAt  DateTime      @default(now())
      updatedAt   DateTime      @updatedAt
      ratings     VideoRating[]
    }
    
    model Comment {
      id               Int             @id @default(autoincrement())
      text             String          @db.VarChar(1000)
      baseCommentId    Int?
      baseComment      Comment?        @relation("baseComment", fields: [baseCommentId], references: [id])
      replies          Comment[]       @relation("baseComment")
      replyToCommentId Int?
      replyToComment   Comment?        @relation("replyToComment", fields: [replyToCommentId], references: [id])
      directReplies    Comment[]       @relation("replyToComment")
      userId           Int
      author           User            @relation(fields: [userId], references: [id])
      videoId          Int
      commentedOnVideo Video           @relation(fields: [videoId], references: [id])
      commentedAt      DateTime        @default(now())
      editedAt         DateTime        @updatedAt
      Rating           CommentRating[]
    }
    
    enum RatingStatus {
      LIKED
      DISLIKED
    }
    
    model VideoRating {
      id      Int          @id @default(autoincrement())
      status  RatingStatus
      userId  Int
      ratedBy User         @relation(fields: [userId], references: [id])
      videoId Int?
      video   Video?       @relation(fields: [videoId], references: [id])
    
      @@unique([videoId, userId])
    }
    
    model CommentRating {
      id        Int          @id @default(autoincrement())
      status    RatingStatus
      userId    Int
      ratedBy   User         @relation(fields: [userId], references: [id])
      commentId Int?
      comment   Comment?     @relation(fields: [commentId], references: [id])
    
      @@unique([commentId, userId])
    }
    
    model Subscriber {
      id        Int  @id @default(autoincrement())
      channelId Int
      channel   User @relation("channel", fields: [channelId], references: [id])
      userId    Int
      user      User @relation("subscriber", fields: [userId], references: [id])
    
      @@unique([channelId, userId])
    }

    I loved prisma until I started to get these kind of errors, please prisma team help everyone out by resolving this issue.
    As @subnomo also said that this occurs when we try to count nested relation. We definitely need this feature (typescript is also fine when I try to do this 😂 but we want prisma to be fine too).

    Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bug/2-confirmedkind/bugtopic: previewFeaturestopic: selectRelationCount

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions