Skip to content
This repository has been archived by the owner on Jan 14, 2021. It is now read-only.

Gracefully handle incorrect id column type #456

Closed
timsuchanek opened this issue Jan 30, 2020 · 10 comments
Closed

Gracefully handle incorrect id column type #456

timsuchanek opened this issue Jan 30, 2020 · 10 comments
Assignees
Labels
bug/2-confirmed We have confirmed that this is a bug. kind/bug A reported bug.
Milestone

Comments

@timsuchanek
Copy link
Contributor

timsuchanek commented Jan 30, 2020

As of now, if I have this schema:

datasource db {
  provider = "sqlite"
  url      = "sqlite:./dev.db"
}

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

model Post {
  id        Int     @id @default(autoincrement())
  title     String
  content   String?
  published Boolean @default(false)
  author    User?
}

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

And the column author in Post has the type text in any SQL database (vs. the Int that is expected via the User.id column), it won't error, but just can't resolve the relation, returning an empty result set.

We should either error in this situation or be able to coerce the type of the author column.

@timsuchanek timsuchanek added bug/2-confirmed We have confirmed that this is a bug. kind/bug A reported bug. process/candidate Candidate for next Milestone. labels Jan 30, 2020
@janpio janpio added this to the Preview 22 milestone Jan 31, 2020
@janpio janpio removed the process/candidate Candidate for next Milestone. label Jan 31, 2020
@Jolg42
Copy link
Member

Jolg42 commented Feb 11, 2020

@timsuchanek

Before / After
Screen Shot 2020-02-11 at 10 47 04

Error is now

Reason: Error occurred during query execution:
InterpretationError("Error for binding \'0\': DomainError(ConversionFailure(\"record identifier\", \"assimilated record identifier\"))")

    at PrismaClientFetcher.request (/Users/j42/Dev/prisma-examples/typescript/script/node_modules/@prisma/client/index.js:82:23)

@janpio
Copy link
Member

janpio commented Feb 11, 2020

DomainError(ConversionFailure("record identifier", "assimilated record identifier"))

What does that mean?

@Jolg42
Copy link
Member

Jolg42 commented Feb 11, 2020

@janpio Tim told the message should be better, here it's a regression from the engine, the error points out that the ID type is not correct. I'll run again soon as the backend is fixed it :)

@mavilein
Copy link
Member

This should be fixed now. Can you test again please @Jolg42 ? 🙏

@Jolg42
Copy link
Member

Jolg42 commented Feb 17, 2020

So it looks like from the Prisma Client there is no error provided like before.

Reproduction example:

Code and SQLite db from:
https://github.com/prisma/prisma-examples/tree/d84af887496a104aa94b214d6301dc4d80ddc266/typescript/script

yarn add prisma2@alpha @prisma/client@alpha
npx prisma2 generate
ts-node script.ts

Latest step of the scripts returns an empty array instead of data
Retrieved all posts from a specific user: []

Note: The SQLite database need to be reverted (or code modified) after each run because of the unique condition

@dpetrick
Copy link

DomainError(ConversionFailure("record identifier", "assimilated record identifier"))

What does that mean?

It's an internal error stating that one set of fields from a result (table A) can't be rolled over into the opposing sides fields (on table B, FK) because they mismatch.

@dpetrick
Copy link

@Jolg42 So you're saying it still doesn't work, am I reading this correctly?

@mavilein
Copy link
Member

@dpetrick : Yes the query engine returns an empty array when it should find related records instead.

@dpetrick
Copy link

Not reproducible, I assume this to be fixed through various merges concerning types and core query handling.

@Jolg42
Copy link
Member

Jolg42 commented Mar 20, 2020

Indeed it works! 🎊

Retrieved all posts from a specific user:  [
  {
    id: 2,
    title: 'Watch the talks from Prisma Day 2019',
    content: 'https://www.prisma.io/blog/z11sg6ipb3i1/',
    published: true
  },
  {
    id: 5,
    title: 'Join the Prisma Slack community',
    content: 'http://slack.prisma.io',
    published: true
  }
]

@Jolg42 Jolg42 closed this as completed Mar 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug/2-confirmed We have confirmed that this is a bug. kind/bug A reported bug.
Projects
None yet
Development

No branches or pull requests

7 participants