Skip to content

include _count leads to error when using Turso #23140

@jharrell

Description

@jharrell

Bug description

When using Turso and attempting to generate an aggregated count, an error similar to the following is thrown

Invalid `prisma.property.findUnique()` invocation:
Inconsistent column data: Conversion failed: expected a either an i64 or a f64 in column '_aggr_count_leases', found null"

This does not occur locally nor when querying a simple SQLite DB

How to reproduce

With a Turso setup, run a query similar to the following

const property = await prisma.property.findUnique({
                    where: { id, managers: { some: { managerId } } },
                    include: {
                        _count: {
                            select: {
                                apartments: true,
                            }
                        },
                    },
                });

Expected behavior

No response

Prisma information

generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["driverAdapters"]
  binaryTargets   = ["native", "debian-openssl-1.1.x"]
  output          = "./generated/client"
}

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

model Property {
  id           String   @id @default(uuid())

  // ...

  managers       ManagesProperty[]
  apartments     Apartment[]
}

model Apartment {
  id            String   @id @default(uuid())

  // ...

  propertyId    String
  property   Property           @relation(fields: [propertyId], references: [id])
  leases     ApartmentLease[]
}

model ApartmentLease {
  id            String          @id @default(uuid())
  apartment     Apartment       @relation(fields: [apartmentId], references: [id])
  apartmentId   String
  lease         Lease           @relation(fields: [leaseId], references: [id])
  leaseId       String
}

model Lease {
  id                   String    @id @default(uuid())

  // ...

  from                 DateTime
  to                   DateTime

  apartments ApartmentLease[]
}

Environment & setup

  • Database: Turso (LibSQL)
  • Bun 1.0.25

Prisma Version

5.5.2

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions