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

Failed to validate the query `Error occurred during query validation & transformation: #1820

Closed
divyenduz opened this issue Mar 11, 2020 · 6 comments
Assignees
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. topic: client types Types in Prisma Client topic: test-utils
Milestone

Comments

@divyenduz
Copy link
Contributor

divyenduz commented Mar 11, 2020

Import the following table into a local MySQL database and introspect it:

CREATE TABLE `q4hat_categories` (
  `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL DEFAULT '',
  `commentable` enum('true','false') NOT NULL DEFAULT 'true',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

Then run the following client call on it:

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

const prisma = new PrismaClient()

async function main() {
  const data = await prisma.q4hat_categories.create({
    data: {
      name: 'Alice',
      commentable: 'true',
    },
  })
  console.log(data)
}

main().finally(() => prisma.disconnect())

Error observed:

divyendusingh [p2-enum-bool]$ node index.js 
(node:8559) UnhandledPromiseRejectionWarning: Error: 
Invalid `prisma.q4hat_categories.create()` invocation in
/Users/divyendusingh/Documents/prisma/p2-enum-bool/index.js:6:46

Failed to validate the query `Error occurred during query validation & transformation:
Mutation (object)
  ↳ createOneq4hat_categories (field)
    ↳ data (argument)
      ↳ q4hat_categoriesCreateInput (object)
        ↳ commentable (field)
          ↳ Value types mismatch. Have: Boolean(true), want: Enum(Internal(InternalEnum { name: "q4hat_categories_commentable", values: [InternalEnumValue { name: "true", database_name: None }, InternalEnumValue { name: "false", database_name: None }] }))` at `.Mutation.createOneq4hat_categories.data.q4hat_categoriesCreateInput.commentable`
    at PrismaClientFetcher.request (/Users/divyendusingh/Documents/prisma/p2-enum-bool/node_modules/@prisma/client/runtime/index.js:1:47071)
    at processTicksAndRejections (internal/process/task_queues.js:85:5)
(node:8559) 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:8559) [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.

Internal notes:

Test utils database(s) affected:

@divyenduz divyenduz added bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. topic: test-utils labels Mar 11, 2020
@janpio janpio added the topic: client types Types in Prisma Client label Mar 11, 2020
@janpio
Copy link
Member

janpio commented Mar 11, 2020

Seems the string "true" becomes a boolean true along the way somewhere:

Value types mismatch. Have: Boolean(true), want: Enum(Internal(InternalEnum { name: "q4hat_categories_commentable", values: [InternalEnumValue { name: "true", database_name: None }, InternalEnumValue { name: "false", database_name: None }] }))

@yovanoc
Copy link

yovanoc commented Mar 15, 2020

I have the same error but with that message

image

@janpio
Copy link
Member

janpio commented Mar 15, 2020

That points to you having a different underlying problem @yovanoc. Can you please create a new issue and include all the relevant information? Thanks.

@timsuchanek
Copy link
Contributor

timsuchanek commented Mar 16, 2020

The problem here is, that we send a query like so to the query engine from TypeScript:

mutation {
  createOneq4hat_categories(data: {
    name: 'Alice'
    commentable: true
  }) {
    ...
  }
}

We do that because enums are represented without "quotes" in the query.
Therefore, the query parser of the query engine needs to be able to distinguish this from the same-looking boolean true.

@dpetrick
Copy link
Contributor

I pushed a fix for the query engine, it should be available shortly on alpha.

@janpio
Copy link
Member

janpio commented Mar 17, 2020

I can confirm this works now 🚀

C:\Users\Jan\Documents\throwaway\1820>node index.js
{ commentable: 'true', id: 1, name: 'Alice' }

C:\Users\Jan\Documents\throwaway\1820>prisma2 -v
Prisma CLI Version   : prisma2@2.0.0-alpha.927
Current platform     : windows
Query Engine         : prisma a50009b3729b0c9187c88c8cf6cebd268881c9bb (at C:\ProgramData\nvm\v12.6.0\node_modules\prisma2\query-engine-windows.exe)
Migration Engine     : migration-engine-cli a50009b3729b0c9187c88c8cf6cebd268881c9bb (at C:\ProgramData\nvm\v12.6.0\node_modules\prisma2\migration-engine-windows.exe)
Introspection Engine : introspection-core a50009b3729b0c9187c88c8cf6cebd268881c9bb (at C:\ProgramData\nvm\v12.6.0\node_modules\prisma2\introspection-engine-windows.exe)

C:\Users\Jan\Documents\throwaway\1820>

Thanks @dpetrick!


Can you test if the test-utils problem is also gone @divyenduz?
Maybe your problem is also fixed @yovanoc although it pointed to an underlying reason? If not, please do open a new issue - we are really interested in fixing this.

@janpio janpio closed this as completed Mar 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. topic: client types Types in Prisma Client topic: test-utils
Projects
None yet
Development

No branches or pull requests

5 participants