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.

Count Relations Error

See original GitHub issue

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

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
joao-oliveira-nexcommented, Jun 6, 2021

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'
}
0reactions
pantharshit00commented, Jul 29, 2021

Closing in favour of https://github.com/prisma/prisma/issues/7331

It describes the same bug.

Read more comments on GitHub >

github_iconTop Results From Across the Web

count self relation on Prisma error: table name specified more ...
This is a known issue with self-relations and we hope to fix it soon. If you want to track this bug, follow this...
Read more >
Aggregating functions - Cypher Manual - Neo4j
Using count(*) to group and count relationship types. The function count(*) can be used to group the type of matched relationships and return...
Read more >
Eloquent: how to where count relation ship ? - Laracasts
I have two models : TeamleaderDeal and Task . the relationship is : TeamleaderDeal model: Copy Code public function tasks() ...
Read more >
Display a relation count in a List via columns.yaml
To display this count value in a List, use the useRelationCount option in your columns.yaml . Using the usual select: count method would...
Read more >
Create and manage relationships in Power BI Desktop
If none of the tables selected for the relationship has unique values, you'll see the following error: One of the columns must have...
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