Prisma-client-js: missing FROM-clause entry for table

Created on 16 Mar 2020  Â·  6Comments  Â·  Source: prisma/prisma-client-js

Started seeing this error again after upgrading from preview21 to preview24 - I say again because it looks like a regression of https://github.com/prisma/prisma-client-js/issues/322, with the error message being identical, save for the for table part now including the actual name of the table rather than an arbitrary identifier like j1.

Example error message thrown during a query:

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("42P01"), message: "missing FROM-clause entry for table \"_ExternalFilesOnBundleVersions\"", detail: None, hint: None, position: Some(Original(268)), where_: None, schema: None, table: None, column: None, datatype: None, constraint: None, file: Some("parse_relation.c"), line: Some(3140), routine: Some("errorMissingRTE") }) }) })
bu2-confirmed kinbug tecengines implicit relation

Most helpful comment

Same problem here (on preview023 and preview024) :(

reproduction:

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[]
  streets Street[]
}

model Street {
  id Int @id @default(autoincrement())
  street String
  users User[]
}

This works:

{
  findManyUser {
    id
    streets {
      id
    }
  }
}

leading to

prisma:query SELECT `dev`.`User`.`id` FROM `dev`.`User` WHERE 1=1 LIMIT ? OFFSET ?
prisma:query SELECT `B`, `A` FROM `dev`.`_StreetToUser` WHERE `B` IN (?,?)
prisma:query SELECT `dev`.`Street`.`id` FROM `dev`.`Street` WHERE 1=0 LIMIT ? OFFSET ?

This fails:

{
  findManyPost {
    id
    author {
      id
      streets {
        id
      }
    }
  }
}

leading to

prisma:query SELECT `dev`.`Post`.`id`, `dev`.`Post`.`author` FROM `dev`.`Post` WHERE 1=1 LIMIT ? OFFSET ?
prisma:query SELECT `dev`.`User`.`id`, `dev`.`_StreetToUser`.`streets` FROM `dev`.`User` WHERE `dev`.`User`.`id` IN (?,?) LIMIT ? OFFSET ?

All 6 comments

Okay, I did some investigating, and it looks like it's not quite a regression - the setup in the previous issue no longer triggers this error. However, I _was_ able to replicate this with the following setup instead:

Schema:

model Foo {
  id String @id @default(cuid())
  a  A[]
}

model A {
  id   String  @id @default(cuid())
  name String?
  foo  Foo?
  b    B[]
}

model B {
  id String @id @default(cuid())
  a  A[]
}

Query:

await db.foo.findMany({
  select: {
    id: true,
    a: {
      select: {
        id: true,
        b: {
          select: {
            id: true
          }
        }
      }
    }
  }
});

This throws the following message:

ConnectorError(ConnectorError { user_facing_error: None, kind: QueryError(Error { kind: Db, cause: Some(DbError { severity: "ERROR", parsed_severity: Some(Error), code: SqlState("42P01"), message: "missing FROM-clause entry for table \"_AToB\"", detail: None, hint: None, position: Some(Original(27)), where_: None, schema: None, table: None, column: None, datatype: None, constraint: None, file: Some("parse_relation.c"), line: Some(3140), routine: Some("errorMissingRTE") }) }) })

Poking around in this setup, I've found that the error goes away if field foo is removed from model A, and field a is removed from model B, so it looks like two way relations may have something to do with this.

Thanks.

Can you possibly set the ENV var DEBUG=* and change your Prisma Client instantiation to const prisma = new PrismaClient({ log: ['query', 'info', 'warn'], }) and post the full output you are getting? Might be helpful later when reproducing.

Same problem here (on preview023 and preview024) :(

reproduction:

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[]
  streets Street[]
}

model Street {
  id Int @id @default(autoincrement())
  street String
  users User[]
}

This works:

{
  findManyUser {
    id
    streets {
      id
    }
  }
}

leading to

prisma:query SELECT `dev`.`User`.`id` FROM `dev`.`User` WHERE 1=1 LIMIT ? OFFSET ?
prisma:query SELECT `B`, `A` FROM `dev`.`_StreetToUser` WHERE `B` IN (?,?)
prisma:query SELECT `dev`.`Street`.`id` FROM `dev`.`Street` WHERE 1=0 LIMIT ? OFFSET ?

This fails:

{
  findManyPost {
    id
    author {
      id
      streets {
        id
      }
    }
  }
}

leading to

prisma:query SELECT `dev`.`Post`.`id`, `dev`.`Post`.`author` FROM `dev`.`Post` WHERE 1=1 LIMIT ? OFFSET ?
prisma:query SELECT `dev`.`User`.`id`, `dev`.`_StreetToUser`.`streets` FROM `dev`.`User` WHERE `dev`.`User`.`id` IN (?,?) LIMIT ? OFFSET ?

Thanks for the reproduction. I was able to reproduce this in both preview024 and the latest alpha :

Prisma CLI Version   : [email protected]
Current platform     : darwin
Query Engine         : prisma 6aa23a61c78a5418a0231347458d639aa337ec1d (at /Users/harshit/.nvm/versions/node/v12.15.0/lib/node_modules/prisma2/query-engine-darwin)
Migration Engine     : migration-engine-cli 6aa23a61c78a5418a0231347458d639aa337ec1d (at /Users/harshit/.nvm/versions/node/v12.15.0/lib/node_modules/prisma2/migration-engine-darwin)
Introspection Engine : introspection-core 6aa23a61c78a5418a0231347458d639aa337ec1d (at /Users/harshit/.nvm/versions/node/v12.15.0/lib/node_modules/prisma2/introspection-engine-darwin)

Debug output(from alpha):

╰─ ts-node index.ts                                                                                                                                                                                                                 ─╯
  prisma-client {
  prisma-client   engineConfig: {
  prisma-client     cwd: '/Users/harshit/code/reproductions/issue-574/prisma',
  prisma-client     debug: false,
  prisma-client     datamodelPath: '/Users/harshit/code/reproductions/issue-574/node_modules/@prisma/client/schema.prisma',
  prisma-client     prismaPath: undefined,
  prisma-client     datasources: [],
  prisma-client     generator: {
  prisma-client       name: 'client',
  prisma-client       provider: 'prisma-client-js',
  prisma-client       output: '/Users/harshit/code/reproductions/issue-574/node_modules/@prisma/client',
  prisma-client       binaryTargets: [],
  prisma-client       config: {}
  prisma-client     },
  prisma-client     showColors: true,
  prisma-client     logLevel: undefined,
  prisma-client     logQueries: undefined,
  prisma-client     env: {
  prisma-client       DATABASE_URL: 'postgresql://harshit:Harshit00@localhost:5432/issue_client_574?schema=public'
  prisma-client     },
  prisma-client     flags: []
  prisma-client   }
  prisma-client } +0ms
  prisma-client Prisma Client call: +8ms
  prisma-client prisma.foo.findMany({
  prisma-client   select: {
  prisma-client     id: true,
  prisma-client     a: {
  prisma-client       select: {
  prisma-client         id: true,
  prisma-client         b: {
  prisma-client           select: {
  prisma-client             id: true
  prisma-client           }
  prisma-client         }
  prisma-client       }
  prisma-client     }
  prisma-client   }
  prisma-client }) +1ms
  prisma-client Generated request: +0ms
  prisma-client query {
  prisma-client   findManyFoo {
  prisma-client     id
  prisma-client     a {
  prisma-client       id
  prisma-client       b {
  prisma-client         id
  prisma-client       }
  prisma-client     }
  prisma-client   }
  prisma-client }
  prisma-client  +0ms
  getos { platform: 'darwin', libssl: undefined } +0ms
  engine {
  engine   PRISMA_DML_PATH: '/Users/harshit/code/reproductions/issue-574/node_modules/@prisma/client/schema.prisma',
  engine   PORT: '58724',
  engine   RUST_BACKTRACE: '1',
  engine   RUST_LOG: 'info',
  engine   OVERWRITE_DATASOURCES: '[]',
  engine   CLICOLOR_FORCE: '1'
  engine } +0ms
  engine { cwd: '/Users/harshit/code/reproductions/issue-574/prisma' } +0ms
  plusX Execution permissions of /Users/harshit/code/reproductions/issue-574/node_modules/@prisma/client/runtime/query-engine-darwin are fine +0ms
  engine { flags: [ '--enable-raw-queries' ] } +1ms
  engine stderr Printing to stderr for debugging +20ms
  engine stderr Listening on 127.0.0.1:58724 +0ms
  engine stdout {
  timestamp: 'Mar 19 14:32:05.064',
  level: 'INFO',
  target: 'quaint::pooled',
  fields: { message: 'Starting a postgresql pool with 9 connections.' }
} +1ms
  engine stdout {
  timestamp: 'Mar 19 14:32:05.070',
  level: 'INFO',
  target: 'prisma::server',
  fields: {
    message: 'Started http server on 127.0.0.1:58724',
    'log.target': 'prisma::server',
    'log.module_path': 'prisma::server',
    'log.file': 'query-engine/prisma/src/server.rs',
    'log.line': 95
  }
} +5ms
  printStack callsite Error
    at Object.s [as Foo] (/Users/harshit/code/reproductions/issue-574/node_modules/@prisma/client/runtime/index.js:1:44641)
    at Object.n.<computed> [as findMany] (/Users/harshit/code/reproductions/issue-574/node_modules/@prisma/client/runtime/index.js:1:46267)
    at /Users/harshit/code/reproductions/issue-574/index.ts:46:53
    at step (/Users/harshit/code/reproductions/issue-574/index.ts:33:23)
    at Object.next (/Users/harshit/code/reproductions/issue-574/index.ts:14:53)
    at /Users/harshit/code/reproductions/issue-574/index.ts:8:71
    at new Promise (<anonymous>)
    at __awaiter (/Users/harshit/code/reproductions/issue-574/index.ts:4:12)
    at main (/Users/harshit/code/reproductions/issue-574/index.ts:42:12)
    at Object.<anonymous> (/Users/harshit/code/reproductions/issue-574/index.ts:69:1) +0ms
(node:24974) UnhandledPromiseRejectionWarning: Error:
Invalid `prisma.foo.findMany()` 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("42P01"), message: "missing FROM-clause entry for table \"_AToB\"", detail: None, hint: None, position: Some(Original(27)), where_: None, schema: None, table: None, column: None, datatype: None, constraint: None, file: Some("parse_relation.c"), line: Some(3240), routine: Some("errorMissingRTE") }) }) })
    at PrismaClientFetcher.request (/Users/harshit/code/reproductions/issue-574/node_modules/@prisma/client/runtime/index.js:1:47490)
    at processTicksAndRejections (internal/process/task_queues.js:94:5)
(node:24974) 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(). (rejection id: 1)
(node:24974) [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.

Reproduction repository: https://github.com/harshit-test-org/prisma2-client-574

Not reproducible anymore on latest alpha / beta.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nikolasburk picture nikolasburk  Â·  3Comments

AhmedElywa picture AhmedElywa  Â·  4Comments

maartenraes picture maartenraes  Â·  4Comments

timsuchanek picture timsuchanek  Â·  4Comments

Errorname picture Errorname  Â·  3Comments