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

Count Relations Error #7483

Closed
joao-oliveira-nex opened this issue Jun 5, 2021 · 5 comments
Closed

Count Relations Error #7483

joao-oliveira-nex opened this issue Jun 5, 2021 · 5 comments
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: _count https://www.prisma.io/docs/concepts/components/prisma-client/aggregation-grouping-summarizing#count-

Comments

@joao-oliveira-nex
Copy link

joao-oliveira-nex commented Jun 5, 2021

Bug description

I'm trying to make an API call that retrieves the count of entries for a related field. I get the following error:

(node:89911) UnhandledPromiseRejectionWarning: Error: 
Invalid `prisma.decider.findMany()` invocation:

Error: 
Invalid `prisma.decider.findUnique()` invocation:


  Error occurred during query execution:
ConnectorError(ConnectorError { user_facing_error: None, kind: QueryError(Error { kind: Db, cause: Some(DbError { severity: "ERROR", parsed_severity: Some(Error), code: SqlState("42804"), message: "argument of JOIN/ON must be type boolean, not type record", detail: None, hint: None, position: Some(Original(354)), where_: None, schema: None, table: None, column: None, datatype: None, constraint: None, file: Some("parse_coerce.c"), line: Some(1163), routine: Some("coerce_to_boolean") }) }) })
    at cb (/Users/joaooliveira/dev/ulreech/node_modules/@prisma/client/runtime/index.js:35227:17)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:90768) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:90768) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. 

How to reproduce

I'm running the following TS script:

import { PrismaClient } from '@prisma/client'

const prisma = new PrismaClient()

async function start () {
    const users = await prisma.decider.findUnique({
        where: {
            slug: 'cocktails'
        },
        select: {
            _count: {
                select: {
                    entries: true
                }
            }
        }
        // include: {
        //     _count: {
        //         entries: true
        //     }
        // }
    });

    console.log(JSON.stringify(users, null, 2));
};


start();

The odd part is that running the "where" condition alone retrieves results.

Expected behavior

Returning something like:

{"decider_id":1,"name":"Cocktails","description":"Cocktails Description","slug":"cocktails", "_count": { "entries": 2}}

Prisma information

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

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

// model Post {
//   post_id   Int     @id @default(autoincrement())
//   content   String?
//   title     String
//   author_id Int?
//   author    User?   @relation(fields: [author_id], references: [user_id])
// }

// model Profile {
//   bio        String?
//   profile_id Int     @id @default(autoincrement())
//   user_id    Int
//   user       User    @relation(fields: [user_id], references: [user_id])
// }

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

model Decider {
  decider_id Int @id @default(autoincrement())
  name String
  description String?
  slug String @unique
  fields Field[]
  entries Entry[]

  @@unique([decider_id, name])
}

model Field {
  field_id Int @id @default(autoincrement())
  name String
  description String?
  type_name String
  type Type @relation(fields: [type_name], references: [name])
  decider_id Int
  decider Decider @relation(fields: [decider_id], references: [decider_id])
  data Data[]

  @@unique([field_id, name])
}

model Data {
  data_id Int @id @default(autoincrement())
  value String?
  entry_id Int
  entry_name String
  entry Entry @relation(fields: [entry_id, entry_name], references: [entry_id, name])
  field_id Int
  field_name String
  field Field @relation(fields: [field_id, field_name], references: [field_id, name])
}

model Entry {
  entry_id Int @id @default(autoincrement())
  name String
  slug String
  data Data[]
  decider_id Int
  decider_name String
  decider Decider @relation(fields: [decider_id, decider_name], references: [decider_id, name])

  @@unique([entry_id, name])
  @@unique([slug, decider_id])
}

model Type {
  type_id Int @id @default(autoincrement())
  name String @unique
  fields Field[]
}

Environment & setup

  • OS: Mac OS
  • Database: PostgreSQL
  • Node.js version: v12.18.2

Prisma Version

2.24.1
@joao-oliveira-nex joao-oliveira-nex added the kind/bug A reported bug. label Jun 5, 2021
@janpio janpio added bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. team/client Issue for team Client. topic: _count https://www.prisma.io/docs/concepts/components/prisma-client/aggregation-grouping-summarizing#count- labels Jun 6, 2021
@janpio
Copy link
Member

janpio commented Jun 6, 2021

Can you enable debugging with the DEBUG=* env var and then post the full output you are getting? Thanks.

@joao-oliveira-nex
Copy link
Author

Sorry! Here's the log with DEBUG=*:

prisma:client Prisma Client call: +31s
  prisma:client prisma.decider.findUnique({
  prisma:client   where: {
  prisma:client     slug: 'cocktails'
  prisma:client   },
  prisma:client   include: {
  prisma:client     _count: {
  prisma:client       select: {
  prisma:client         entries: true
  prisma:client       }
  prisma:client     }
  prisma:client   }
  prisma:client }) +1ms
  prisma:client Generated request: +0ms
  prisma:client query {
  prisma:client   findUniqueDecider(where: {
  prisma:client     slug: "cocktails"
  prisma:client   }) {
  prisma:client     decider_id
  prisma:client     name
  prisma:client     description
  prisma:client     slug
  prisma:client     _count {
  prisma:client       entries
  prisma:client     }
  prisma:client   }
  prisma:client }
  prisma:client  +0ms
  prisma:engine {
  prisma:engine   error: PrismaClientUnknownRequestError2 [PrismaClientUnknownRequestError]: Error occurred during query execution:
  prisma:engine   ConnectorError(ConnectorError { user_facing_error: None, kind: QueryError(Error { kind: Db, cause: Some(DbError { severity: "ERROR", parsed_severity: Some(Error), code: SqlState("42804"), message: "argument of JOIN/ON must be type boolean, not type record", detail: None, hint: None, position: Some(Original(442)), where_: None, schema: None, table: None, column: None, datatype: None, constraint: None, file: Some("parse_coerce.c"), line: Some(1163), routine: Some("coerce_to_boolean") }) }) })
  prisma:engine       at NodeEngine.graphQLToJSError (/Users/joaooliveira/dev/ulreech/node_modules/@prisma/client/runtime/index.js:28377:14)
  prisma:engine       at NodeEngine.request (/Users/joaooliveira/dev/ulreech/node_modules/@prisma/client/runtime/index.js:28273:24)
  prisma:engine       at processTicksAndRejections (internal/process/task_queues.js:97:5) {
  prisma:engine     clientVersion: '2.24.1'
  prisma:engine   }
  prisma:engine } +31s
  prisma:engine {
  prisma:engine   error: PrismaClientUnknownRequestError2 [PrismaClientUnknownRequestError]: Error occurred during query execution:
  prisma:engine   ConnectorError(ConnectorError { user_facing_error: None, kind: QueryError(Error { kind: Db, cause: Some(DbError { severity: "ERROR", parsed_severity: Some(Error), code: SqlState("42804"), message: "argument of JOIN/ON must be type boolean, not type record", detail: None, hint: None, position: Some(Original(442)), where_: None, schema: None, table: None, column: None, datatype: None, constraint: None, file: Some("parse_coerce.c"), line: Some(1163), routine: Some("coerce_to_boolean") }) }) })
  prisma:engine       at NodeEngine.graphQLToJSError (/Users/joaooliveira/dev/ulreech/node_modules/@prisma/client/runtime/index.js:28377:14)
  prisma:engine       at NodeEngine.request (/Users/joaooliveira/dev/ulreech/node_modules/@prisma/client/runtime/index.js:28273:24)
  prisma:engine       at processTicksAndRejections (internal/process/task_queues.js:97:5) {
  prisma:engine     clientVersion: '2.24.1'
  prisma:engine   }
  prisma:engine } +3ms
  prisma:engine {
  prisma:engine   error: PrismaClientUnknownRequestError2 [PrismaClientUnknownRequestError]: Error occurred during query execution:
  prisma:engine   ConnectorError(ConnectorError { user_facing_error: None, kind: QueryError(Error { kind: Db, cause: Some(DbError { severity: "ERROR", parsed_severity: Some(Error), code: SqlState("42804"), message: "argument of JOIN/ON must be type boolean, not type record", detail: None, hint: None, position: Some(Original(442)), where_: None, schema: None, table: None, column: None, datatype: None, constraint: None, file: Some("parse_coerce.c"), line: Some(1163), routine: Some("coerce_to_boolean") }) }) })
  prisma:engine       at NodeEngine.graphQLToJSError (/Users/joaooliveira/dev/ulreech/node_modules/@prisma/client/runtime/index.js:28377:14)
  prisma:engine       at NodeEngine.request (/Users/joaooliveira/dev/ulreech/node_modules/@prisma/client/runtime/index.js:28273:24)
  prisma:engine       at processTicksAndRejections (internal/process/task_queues.js:97:5) {
  prisma:engine     clientVersion: '2.24.1'
  prisma:engine   }
  prisma:engine } +3ms
  prisma:client Error: Error occurred during query execution:
  prisma:client ConnectorError(ConnectorError { user_facing_error: None, kind: QueryError(Error { kind: Db, cause: Some(DbError { severity: "ERROR", parsed_severity: Some(Error), code: SqlState("42804"), message: "argument of JOIN/ON must be type boolean, not type record", detail: None, hint: None, position: Some(Original(442)), where_: None, schema: None, table: None, column: None, datatype: None, constraint: None, file: Some("parse_coerce.c"), line: Some(1163), routine: Some("coerce_to_boolean") }) }) })
  prisma:client     at NodeEngine.graphQLToJSError (/Users/joaooliveira/dev/ulreech/node_modules/@prisma/client/runtime/index.js:28377:14)
  prisma:client     at NodeEngine.request (/Users/joaooliveira/dev/ulreech/node_modules/@prisma/client/runtime/index.js:28273:24)
  prisma:client     at processTicksAndRejections (internal/process/task_queues.js:97:5) +23ms
PrismaClientUnknownRequestError2 [PrismaClientUnknownRequestError]: 
Invalid `prisma.decider.findUnique()` invocation:


  Error occurred during query execution:
ConnectorError(ConnectorError { user_facing_error: None, kind: QueryError(Error { kind: Db, cause: Some(DbError { severity: "ERROR", parsed_severity: Some(Error), code: SqlState("42804"), message: "argument of JOIN/ON must be type boolean, not type record", detail: None, hint: None, position: Some(Original(442)), where_: None, schema: None, table: None, column: None, datatype: None, constraint: None, file: Some("parse_coerce.c"), line: Some(1163), routine: Some("coerce_to_boolean") }) }) })
    at cb (/Users/joaooliveira/dev/ulreech/node_modules/@prisma/client/runtime/index.js:35227:17)
    at processTicksAndRejections (internal/process/task_queues.js:97:5) {
  clientVersion: '2.24.1'
}

@sandbox-apps
Copy link

I also experience this problem. Where the posts include author and count comments, reactions. With same error output above. I wonder why on that specific schema it doesnt work while count on other model works fine...

This features killing me as one of the common attributes of a social apps is counts

@sandbox-apps
Copy link

Just to correct my statement, I've encountered it again on nested table like example: groups/:groupId/posts and groups/:groupId/posts/:postId/comments where on top level group they are working fine.

@pantharshit00
Copy link
Contributor

Closing in favour of #7331

It describes the same bug.

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: _count https://www.prisma.io/docs/concepts/components/prisma-client/aggregation-grouping-summarizing#count-
Projects
None yet
Development

No branches or pull requests

4 participants