prisma / prisma/orm

Using $queryRaw with `pg_sleep` crashes

Open
#3,530 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug/2-confirmed kind/bug status/needs-action tech/engines topic: broken query topic: postgresql topic: raw
Dominant language
TypeScript
Stars
47.6k
Forks
2.5k
Avg merge
21h 59m
Merged PRs (30d)
95

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the report with a generated client using the Postgres provider, comparing $queryRaw with $executeRaw and the SELECT pg_sleep(1) entry point. Trace the raw-query handling that produces the deserialization error, then verify that the query completes without crashing and add regression coverage for this case.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js, postgresql
Domain
api, database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.