prisma / prisma

Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server, SQLite, MongoDB and CockroachDB
https://www.prisma.io
Apache License 2.0
39.3k stars 1.54k forks source link

Using $queryRaw with `pg_sleep` crashes #3530

Open divyenduz opened 4 years ago

divyenduz commented 4 years ago

Bug description

Executing a SELECT pg_sleep(1) query with $queryRaw crashes. It works with $executeRaw. The problem is specific to Postgres.

How to reproduce

  1. Generate a client with Postgres provider and run
const { PrismaClient } = require('@prisma/client')

const prisma = new PrismaClient()

async function main() {
  await prisma.$queryRaw(`SELECT pg_sleep(1);`)
}

main()
  .catch((e) => {
    console.log(e)
  })
  .finally(() => {
    prisma.$disconnect()
  })
  1. Observe error
divyendusingh [p2-raw-sleep]$ node index.js                                                                                       130 ↵
PrismaClientKnownRequestError: 
Invalid `prisma.queryRaw()` invocation:

  Raw query failed. Code: `N/A`. Message: `error deserializing column 0: cannot convert between the Rust type `core::option::Option<alloc::string::String>` and the Postgres type `void``
    at PrismaClientFetcher.request (/Users/divyendusingh/Documents/prisma/triage/p2-raw-sleep/node_modules/@prisma/client/runtime/index.js:1:228179)
    at processTicksAndRejections (internal/process/task_queues.js:97:5) {
  code: 'P2010',
  meta: {
    code: 'N/A',
    message: 'error deserializing column 0: cannot convert between the Rust type `core::option::Option<alloc::string::String>` and the Postgres type `void`'
  }
}

Expected behavior

It shouldn't crash.

Prisma information

divyendusingh [p2-raw-sleep]$ yarn prisma --version                                                                               130 ↵
yarn run v1.22.4
$ /Users/divyendusingh/Documents/prisma/triage/p2-raw-sleep/node_modules/.bin/prisma --version
@prisma/cli          : 2.7.0-dev.11
Current platform     : darwin
Query Engine         : query-engine 7c19ae69057b1b46b2e7f90d531d99909cc85502 (at node_modules/@prisma/cli/query-engine-darwin)
Migration Engine     : migration-engine-cli 7c19ae69057b1b46b2e7f90d531d99909cc85502 (at node_modules/@prisma/cli/migration-engine-darwin)
Introspection Engine : introspection-core 7c19ae69057b1b46b2e7f90d531d99909cc85502 (at node_modules/@prisma/cli/introspection-engine-darwin)
Format Binary        : prisma-fmt 7c19ae69057b1b46b2e7f90d531d99909cc85502 (at node_modules/@prisma/cli/prisma-fmt-darwin)
Studio               : 0.273.0
✨  Done in 1.79s.
pantharshit00 commented 3 years ago

This is still reproducible in 2.21

janpio commented 3 years ago

DBeaver display the result as an empty cell: image

janpio commented 3 years ago

From internal discussion: Our Rust postgres library we are using can not map this void value coming back here. Right now the "solution" is to use $executeRaw and not $queryRaw.

pantharshit00 commented 3 years ago

Still reproducible but doesn't seem to be an important issue.

Jolg42 commented 2 years ago

Can reproduce on our internal dev version 4.4.0-dev.30, queryRaw fails, executeRaw works.

PrismaClientKnownRequestError: 
Invalid `prisma.$queryRaw()` invocation:

Raw query failed. Code: `N/A`. Message: `Failed to deserialize column of type 'void'. If you're using $queryRaw and this column is explicitly marked as `Unsupported` in your Prisma schema, try casting this column to any supported Prisma type such as `String`.`
    at RequestHandler.handleRequestError (/Users/j42/Repros/14999/node_modules/@prisma/client/runtime/index.js:30850:13)
    at RequestHandler.request (/Users/j42/Repros/14999/node_modules/@prisma/client/runtime/index.js:30833:12)
    at async Proxy._request (/Users/j42/Repros/14999/node_modules/@prisma/client/runtime/index.js:31805:16)
    at async /Users/j42/Repros/14999/main.ts:52:3 {
  code: 'P2010',
  clientVersion: '4.4.0-dev.30',
  meta: {
    code: 'N/A',
    message: "Failed to deserialize column of type 'void'. If you're using $queryRaw and this column is explicitly marked as `Unsupported` in your Prisma schema, try casting this column to any supported Prisma type such as `String`."
  }
}