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

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

Closed
mostafa7904 opened this issue May 14, 2021 · 3 comments
Assignees
Labels
bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. kind/bug A reported bug. team/client Issue for team Client. topic: basic error report topic: selectRelationCount
Milestone

Comments

@mostafa7904
Copy link

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

Versions

Name Version
Node v14.16.1
OS windows
Prisma Client 2.22.1
Query Engine query-engine 60cc71d884972ab4e897f0277c4b84383dddaf6c
Database undefined

Query

query {
  findUniqueUser(where: {
    username: "X"
  }) {
    id
    username
    email
    password
    avatar
    header_img
    created_at
    bio
    deleted
    card_number
    goal
    payment_frequency
    full_name
    profession
    verified
    social_media
    type
    posts(
      where: {
        deleted: false
      }
      orderBy: [
        {
          created_at: desc
        }
      ]
      take: 5
    ) {
      title
      text
      _count {
        likes
        comments
      }
    }
  }
}

Logs

  prisma:tryLoadEnv Environment variables loaded from D:\Projects\patreon-back\.env  
  prisma:tryLoadEnv Environment variables loaded from D:\Projects\patreon-back\.env  
  prisma:client clientVersion: 2.22.1  
  prisma:engine { cwd: 'D:\\Projects\\patreon-back\\prisma' }  
  prisma:engine Search for Query Engine in D:\Projects\patreon-back\node_modules\.prisma\client  
  prisma:engine Search for Query Engine in D:\Projects\patreon-back\node_modules\.prisma\client  
  prisma:engine { flags: [ '--enable-raw-queries', '--port', '56935' ] }  
  prisma:engine stdout  Starting a mysql pool with 9 connections.  
  prisma:engine stdout  Started http server on http://127.0.0.1:56935  
  prisma:engine Search for Query Engine in D:\Projects\patreon-back\node_modules\.prisma\client  
  prisma:engine Stopping Prisma engine4  
  prisma:engine Waiting for start promise  
  prisma:engine Done waiting for start promise  
  prisma:engine Client Version: 2.22.1  
  prisma:engine Engine Version: query-engine 60cc71d884972ab4e897f0277c4b84383dddaf6c  
  prisma:engine Active provider: mysql  
  prisma:engine { cwd: 'D:\\Projects\\patreon-back\\prisma' }  +6s
  prisma:engine Search for Query Engine in D:\Projects\patreon-back\node_modules\.prisma\client  
  prisma:engine { flags: [ '--enable-raw-queries', '--port', '56954' ] }  
  prisma:engine stdout  Starting a mysql pool with 9 connections.  
  prisma:engine stdout  Started http server on http://127.0.0.1:56954  
  prisma:engine Search for Query Engine in D:\Projects\patreon-back\node_modules\.prisma\client  
  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: "Post" }  
  prisma:engine {
  prisma:engine   error: Error: read ECONNRESET
  prisma:engine       at TCP.onStreamRead (internal/stream_base_commons.js:209:20) {
  prisma:engine     errno: -4077,
  prisma:engine     code: 'ECONNRESET',
  prisma:engine     syscall: 'read'
  prisma:engine   }
  prisma:engine }  
  prisma:engine {
  prisma:engine   error: Error: write ECONNRESET
  prisma:engine       at afterWriteDispatched (internal/stream_base_commons.js:156:25)
  prisma:engine       at writevGeneric (internal/stream_base_commons.js:139:3)
  prisma:engine       at Socket._writeGeneric (net.js:783:11)
  prisma:engine       at Socket._writev (net.js:792:8)
  prisma:engine       at doWrite (internal/streams/writable.js:375:12)
  prisma:engine       at clearBuffer (internal/streams/writable.js:521:5)
  prisma:engine       at Socket.Writable.uncork (internal/streams/writable.js:317:7)
  prisma:engine       at write (D:\Projects\patreon-back\node_modules\@prisma\client\runtime\index.js:25825:14)
  prisma:engine       at _resume (D:\Projects\patreon-back\node_modules\@prisma\client\runtime\index.js:25731:31)
  prisma:engine       at resume (D:\Projects\patreon-back\node_modules\@prisma\client\runtime\index.js:25630:5) {
  prisma:engine     errno: -4077,
  prisma:engine     code: 'ECONNRESET',
  prisma:engine     syscall: 'write'
  prisma:engine   }
  prisma:engine }  
  prisma:engine {
  prisma:engine   error: Error: connect ECONNREFUSED 127.0.0.1:56954
  prisma:engine       at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16) {
  prisma:engine     errno: -4078,
  prisma:engine     code: 'ECONNREFUSED',
  prisma:engine     syscall: 'connect',
  prisma:engine     address: '127.0.0.1',
  prisma:engine     port: 56954
  prisma:engine   }
  prisma:engine }  

Client Snippet

const result = await db.user.findUnique({
  where: {
    username,
  },
  select: {
    posts: {
      where: {
        deleted: false,
      },
      orderBy: {
        created_at: "desc",
      },
      take: 5,
      select: {
        _count: {
          select: {
            comments: true,
            likes: true,
          },
        },
      },
    },
  },
});

Schema

generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["selectRelationCount"]
}

datasource db {
  provider = "mysql"
  url      = env("DATABASE_URL")
}
model Post {
  id         Int        @id @default(autoincrement())
  title      String     @db.VarChar(250)
  text       String?    @db.Text
  poll       Poll[]     @relation(name: "pollPost")
  created_at DateTime   @default(now()) @db.DateTime(6)
  userId     Int
  author     User       @relation(name: "posts", fields: [userId], references: [id])
  comments   Comments[]
  likes      Likes[]    @relation(name: "postLikes")
  protected  Boolean    @default(true)
  images     Json?
  audio      String?
  deleted    Boolean    @default(false)

  @@index([userId, created_at])
  @@map("posts")
}
model Comments {
  id         Int      @id @default(autoincrement())
  created_at DateTime @default(now()) @db.DateTime(6)
  likes      Int
  replies    Int
  userId     Int
  postId     Int
  post       Post     @relation(fields: [postId], references: [id])
  author     User     @relation(fields: [userId], references: [id])

  @@map("comments")
}
model Likes {
  id     Int  @id @default(autoincrement())
  userId Int
  postId Int
  User   User @relation("userLikes", fields: [userId], references: [id])
  Post   Post @relation("postLikes", fields: [postId], references: [id])

  @@unique([userId, postId])
  @@map("likes")
}

The issue gets fixed when i remove _count

@janpio janpio added bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. kind/bug A reported bug. topic: basic error report topic: selectRelationCount team/client Issue for team Client. process/candidate labels May 18, 2021
@dpetrick dpetrick self-assigned this May 19, 2021
@matthewmueller matthewmueller added this to the 2.24.0 milestone May 19, 2021
@pantharshit00
Copy link
Contributor

Hey @mostafa7904

Can you please share the User model here as well?

@mostafa7904
Copy link
Author

Sure.

model User {
  id                Int           @id @default(autoincrement())
  username          String        @unique @db.VarChar(255)
  email             String        @unique @db.VarChar(255)
  password          String        @db.VarChar(255)
  avatar            String?       @db.VarChar(250)
  header_img        String?       @db.VarChar(250)
  created_at        DateTime      @default(now()) @db.DateTime(6)
  bio               String?       @db.Text
  deleted           Boolean       @default(false)
  card_number       String?       @db.VarChar(16)
  goal              Int?
  payment_frequency String?       @db.VarChar(15)
  full_name         String?       @db.VarChar(250)
  profession        String?       @db.VarChar(25)
  posts             Post[]        @relation(name: "posts")
  likes             Likes[]       @relation(name: "userLikes")
  comments          Comments[]
  memberships       MemberShips[]
  verified          Boolean       @default(false)
  social_media      Json?
  supporters        Supporters[]
  supportings       Supportings[]
  type              Roles         @default(USER)
  updatedAt         DateTime      @updatedAt

  @@index([email, username])
  @@map("users")
}

@janpio
Copy link
Member

janpio commented May 22, 2021

This is a duplicate of #6543 Please follow that issue for a fix or information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. kind/bug A reported bug. team/client Issue for team Client. topic: basic error report topic: selectRelationCount
Projects
None yet
Development

No branches or pull requests

5 participants