Skip to content

Panic when trying to use Uuid native type with insensitive filters #5311

Closed as not planned

Description

@pantharshit00

Bug description

When the following query where id is @postgres.Uuid type is executed prisma is throwing the following panic:

 const data = await prisma.user.findMany({
    where: {
      id: {
        mode: "insensitive",
        contains: "something",
      },
    },
  });
(node:9993) UnhandledPromiseRejectionWarning: Error:
Invalid `prisma.user.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("42883"), message: "function lower(uuid) does not exist", detail: None, hint: Some("No function matches the given name and argument types. You might need to add explicit type casts."), position: Some(Original(105)), where_: None, schema: None, table: None, column: None, datatype: None, constraint: None, file: Some("parse_func.c"), line: Some(627), routine: Some("ParseFuncOrColumn") }) }) })
    at PrismaClientFetcher.request (/home/harshit/code/reproductions/issue-3447-studio/node_modules/@prisma/client/runtime/index.js:78461:15)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at main (/home/harshit/code/reproductions/issue-3447-studio/main.ts:6:16)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:9993) 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(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:9993) [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.

How to reproduce

See: https://github.com/harshit-test-org/issue-prisma-5311

Expected behavior

Prisma should not ever generate this invalid sql.

Prisma information

See the reproduction posted above

Environment & setup

  • OS: Ubuntu 20.04 via WSL
  • Database: Postgres 12 (docker)
  • Node.js version: 14.15.2
  • Prisma version:
@prisma/cli          : 2.16.0-dev.23
@prisma/client       : 2.16.0-dev.25
Current platform     : debian-openssl-1.1.x
Query Engine         : query-engine 874f616fce40a665d24867f42e602ce8b5ed2cd7 (at node_modules/@prisma/engines/query-engine-debian-openssl-1.1.x)
Migration Engine     : migration-engine-cli 874f616fce40a665d24867f42e602ce8b5ed2cd7 (at node_modules/@prisma/engines/migration-engine-debian-openssl-1.1.x)
Introspection Engine : introspection-core 874f616fce40a665d24867f42e602ce8b5ed2cd7 (at node_modules/@prisma/engines/introspection-engine-debian-openssl-1.1.x)
Format Binary        : prisma-fmt 874f616fce40a665d24867f42e602ce8b5ed2cd7 (at node_modules/@prisma/engines/prisma-fmt-debian-openssl-1.1.x)
Studio               : 0.343.0
Preview Features     : nativeTypes

Activity

  1. skworden commented on Jan 28, 2021

    @skworden

    I also get the same error when filtering a uuid column using "equals" in Prisma Studio. It works using "in" and adding the uuid value in the array. I haven't tried other types.

  2. added this to the 2.17.0 milestone on Feb 3, 2021
  3. flaviaan commented on Feb 8, 2021

    @flaviaan
    Contributor

    After investigating the issue, the conclusion is that we're not yet in a position to fix that issue. We'll get back to it once the Query Engine can deal with native types more granularly.

  4. matthewmueller commented on Feb 8, 2021

    @matthewmueller
    Contributor

    To elaborate on @Weakky's comment: we use the underlying database as much as possible. For Postgres, the query would look like this:

    select * from users where id = lower($1::uuid)

    Unfortunately lower does not accept a uuid as an input. In the future, we may disable this API so you can't run into this runtime error, but we're not there yet.

  5. removed this from the 2.17.0 milestone on Feb 17, 2021
  6. pantharshit00 commented on May 4, 2021

    @pantharshit00
    ContributorAuthor

    This is still reproducible in 2.22.

  7. assigned and unassigned on Sep 7, 2022
  8. Jolg42 commented on Sep 7, 2022

    @Jolg42
    Contributor

    Can reproduce in our internal dev version 4.4.0-dev.30

    Note: The message is now different

    ts-node main.ts    
    /Users/j42/Repros/5311/node_modules/@prisma/client/runtime/index.js:30854
          throw new PrismaClientUnknownRequestError(message, this.client._clientVersion);
                ^
    PrismaClientUnknownRequestError: 
    Invalid `prisma.user.findMany()` invocation in
    /Users/j42/Repros/5311/main.ts:6:34
    
      3 async function main() {
      4   const prisma = new PrismaClient();
      5 
    → 6   const data = await prisma.user.findMany(
    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(E42883), message: "operator does not exist: uuid ~~* unknown", detail: None, hint: Some("No operator matches the given name and argument type(s). You might need to add explicit type casts."), position: Some(Original(126)), where_: None, schema: None, table: None, column: None, datatype: None, constraint: None, file: Some("parse_oper.c"), line: Some(728), routine: Some("op_error") }) }) })
        at RequestHandler.handleRequestError (/Users/j42/Repros/5311/node_modules/@prisma/client/runtime/index.js:30854:13)
        at RequestHandler.request (/Users/j42/Repros/5311/node_modules/@prisma/client/runtime/index.js:30833:12)
        at async PrismaClient._request (/Users/j42/Repros/5311/node_modules/@prisma/client/runtime/index.js:31805:16)
        at async main (/Users/j42/Repros/5311/main.ts:6:16) {
      clientVersion: '4.4.0-dev.30'
    }
    
  9. Jolg42 commented on Oct 21, 2022

    @Jolg42
    Contributor

    This cannot be reproduced since 4.4.0, it now errors with a TypeScript error (also on 4.5.0)

        return new TSError(diagnosticText, diagnosticCodes, diagnostics);
               ^
    TSError: ⨯ Unable to compile TypeScript:
    main.ts:10:9 - error TS2322: Type '{ mode: "insensitive"; contains: string; }' is not assignable to type 'string | UuidFilter | undefined'.
      Object literal may only specify known properties, and 'contains' does not exist in type 'UuidFilter'.
    
    10         contains: "something",
               ~~~~~~~~~~~~~~~~~~~~~
    
        at createTSError (/Users/j42/.nvm/versions/node/v16.16.0/lib/node_modules/ts-node/src/index.ts:859:12)
        at reportTSError (/Users/j42/.nvm/versions/node/v16.16.0/lib/node_modules/ts-node/src/index.ts:863:19)
        at getOutput (/Users/j42/.nvm/versions/node/v16.16.0/lib/node_modules/ts-node/src/index.ts:1077:36)
        at Object.compile (/Users/j42/.nvm/versions/node/v16.16.0/lib/node_modules/ts-node/src/index.ts:1433:41)
        at Module.m._compile (/Users/j42/.nvm/versions/node/v16.16.0/lib/node_modules/ts-node/src/index.ts:1617:30)
        at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
        at Object.require.extensions.<computed> [as .ts] (/Users/j42/.nvm/versions/node/v16.16.0/lib/node_modules/ts-node/src/index.ts:1621:12)
        at Module.load (node:internal/modules/cjs/loader:981:32)
        at Function.Module._load (node:internal/modules/cjs/loader:822:12)
        at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12) {
      diagnosticCodes: [ 2322 ]
    }
    
  10. added this to the 4.4.0 milestone on Oct 21, 2022
  11. Jolg42 commented on Oct 21, 2022

    @Jolg42
    Contributor

    This issue was a duplicate of #9007

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug/2-confirmedkind/bugtopic: native database typestopic: postgresqltopic: uuid

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions