Skip to content

Inconsistent column data: Unexpected conversion failure from Number to BigInt error when using @prisma/adapter-pg  #23926

Description

@chris-addison

Hi all, I've hit an issue when trying out the @prisma/adapter-pg preview feature.

I'm using the latest v5.13.0 and I can resolve the issue by removing the "relationJoins" from the preview features

Here's the error I'm seeing in the console:

  20     include: { user: true },
  21 };
  22 
→ 23 const result = await this.#prisma.baseUser.findUnique(
Inconsistent column data: Unexpected conversion failure for field User.intId from Number(1374511782084.0) to BigInt.
    at In.handleRequestError (/**/node_modules/@prisma/client/runtime/library.js:122:6854)
    at In.handleAndLogRequestError (/**/node_modules/@prisma/client/runtime/library.js:122:6188)
    at In.request (/**/node_modules/@prisma/client/runtime/library.js:122:5896)
    at l (/**/node_modules/@prisma/client/runtime/library.js:127:11167)
    at PrismaUserRepository.getUnsafe (/**/src/infrastructure/repository/v2/prisma/prisma-user.repository.ts:23:24)

Here's roughly how I'm calling Prisma:

async function getUnsafe(id: string | bigint): Promise<User | null> {
    const query = {
        where: typeof id === 'bigint' ? { intId: id } : { id },
        include: { user: true },
    };

    const result = await prisma.baseUser.findUnique(query);
    if (!result) {
        return null;
    }

    return toUser(result);
}

type PrismaBaseUser = Prisma.BaseUserGetPayload<{ include: { user: true } }>;

function toUser(user: PrismaBaseUser): User {
    return {
        id: user.id,
        intId: user.intId,
        name: user.user.name,
        email: user.user.email,
        avatarUrl: user.user.avatar,
    };
}

Here's a subset of my schema:

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

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

model BaseUser {
  id                String       @id @db.Uuid
  intId             BigInt       @unique
  createdAt         DateTime     @default(now())
  updatedAt         DateTime     @updatedAt
  favorites         Repository[] @relation("UserFavorites")
  ownedRepositories Repository[]
  user              User         @relation("userById", fields: [id], references: [id])
  userByIntId       User         @relation("userByIntId", fields: [intId], references: [intId])

  // Indexing intId for faster lookups
  @@index([intId(ops: Int8BloomOps)], type: Brin)
}

model User {
  id              String    @id @db.Uuid
  correlationId   String    @unique @db.Uuid
  intId           BigInt    @unique
  name            String
  email           String?
  locale          String?
  avatar          String?
  createdAt       DateTime  @default(now())
  updatedAt       DateTime
  deletedAt       DateTime?
  baseUser        BaseUser? @relation("userById")
  baseUserByIntId BaseUser? @relation("userByIntId")

  // Indexing intId for faster lookups
  @@index([intId(ops: Int8BloomOps)], type: Brin)
  // Indexing email for faster lookups
  @@index([email], type: Hash)
}

Activity

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions