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

PrismaStudio Obscures Error with Database Having First Row/Record as Duplicate of Column/Field Names #1227

Open
emiliodacosta opened this issue Mar 29, 2024 · 0 comments
Labels
bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. team/client Issue for team Client. topic: studio

Comments

@emiliodacosta
Copy link

emiliodacosta commented Mar 29, 2024

Bug description

When I ran node prisma.js, I received the following error:

PrismaClientKnownRequestError:
Invalid `prisma.patient.findMany()` invocation in
/Users/emidac/Documents/code/aura/aura-patients-app/prisma.js:7:44

  4
  5 async function main() {
  6   // ... you will write your Prisma Client queries here
→ 7   const allPatients = await prisma.patient.findMany(
Inconsistent column data: Could not convert value "age" of the field `age` to type `Int`.
    at In.handleRequestError (/Users/emidac/Documents/code/aura/aura-patients-app/node_modules/@prisma/client/runtime/library.js:122:6854)
    at In.handleAndLogRequestError (/Users/emidac/Documents/code/aura/aura-patients-app/node_modules/@prisma/client/runtime/library.js:122:6188)
    at In.request (/Users/emidac/Documents/code/aura/aura-patients-app/node_modules/@prisma/client/runtime/library.js:122:5896)
    at async l (/Users/emidac/Documents/code/aura/aura-patients-app/node_modules/@prisma/client/runtime/library.js:127:10871)
    at async main (/Users/emidac/Documents/code/aura/aura-patients-app/prisma.js:7:23) {
  code: 'P2023',
  clientVersion: '5.11.0',
  meta: {
    modelName: 'Patient',
    message: 'Could not convert value "age" of the field `age` to type `Int`.'
  }
}

Initially, I thought that the PrismaClient was mistakenly treating my Column/Field Names as a row/record of values.

Instead, it turns out that my Database did, in fact, have a first row/record populated with TEXT/String values replicating the Column/Field Names rather than valid values such as an INTEGER/Int value for the "age" field.
Screenshot 2024-03-29 at 1 51 18 PM

However, before I went to double-check in DB Browser for SQLite, what I saw in Prisma Studio actually confused me further as it didn't show this first problematic row:
Screenshot 2024-03-29 at 1 11 38 PM

How to reproduce

  1. Create a db with the first row/record incorrectly containing Column/Field Names in which the correct value type of one of the fields is supposed to be an INTEGER/Int
  2. View the db in Prisma Studio
  3. See no evidence of the problematic row/record

Expected behavior

I expect Prisma Studio to show me the problematic row/record rather than obscure it

Prisma information

generator client {
  provider = "prisma-client-js"
}

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

model Patient {
  name              String  @id @unique
  firstName         String  @map("first_name")
  age               Int
  height            Int
  weight            Int
  gender            String
  medications       String
  bodyTemperatures  String  @map("body_temperatures")

  @@map("patient")
}
const { PrismaClient } = require('@prisma/client')

const prisma = new PrismaClient()

async function main() {
  // ... you will write your Prisma Client queries here
  const allPatients = await prisma.patient.findMany()
  console.log(allPatients.map((patient) => patient.name))
}

main()
  .then(async () => {
    await prisma.$disconnect()
  })
  .catch(async (e) => {
    console.error(e)
    await prisma.$disconnect()
    process.exit(1)
  })

Environment & setup

  • OS: macOS Sonoma 14.4
  • Architecture: arm64
  • Database: SQLite
  • Node.js version: 20.11.1

Prisma Version

5.11.0
@emiliodacosta emiliodacosta added the kind/bug A reported bug. label Mar 29, 2024
@emiliodacosta emiliodacosta changed the title PrismaClient seems to be treating Column Name as a Value PrismaStudio Obscures Error with Database Having First Row/Record as Duplicate of Column/Field Names Mar 29, 2024
@jkomyno jkomyno added bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. topic: studio team/client Issue for team Client. labels Apr 3, 2024
@janpio janpio transferred this issue from prisma/prisma Apr 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. team/client Issue for team Client. topic: studio
Projects
None yet
Development

No branches or pull requests

2 participants