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

PANIC: called Result::unwrap() on an Err value: Any { .. } in query-engine/connectors/sql-query-connector/src/error.rs:58:51 #12641

Closed
ChristianMoesl opened this issue Apr 2, 2022 · 3 comments · Fixed by prisma/prisma-engines#2902
Labels
bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. kind/bug A reported bug. team/client Issue for team Client. topic: raw $queryRaw(Unsafe) and $executeRaw(Unsafe): https://www.prisma.io/docs/concepts/components/prisma-cli
Milestone

Comments

@ChristianMoesl
Copy link

ChristianMoesl commented Apr 2, 2022

Hi Prisma Team! My Prisma Client just crashed. This is the report:
%23%23 Versions

Name Version
Node v16.14.1
OS darwin-arm64
Prisma Client 3.11.1
Query Engine 0.1.0
Database postgresql

%23%23 Logs

raryStarted: true
prisma:client:libraryEngine sending request, this.libraryStarted: true
prisma:client:libraryEngine sending request, this.libraryStarted: true
prisma:client:libraryEngine sending request, this.libraryStarted: true
prisma:client:libraryEngine sending request, this.libraryStarted: true
prisma:client:libraryEngine sending request, this.libraryStarted: true
prisma:client:libraryEngine sending request, this.libraryStarted: true
prisma:client:libraryEngine sending request, this.libraryStarted: true
prisma:client:libraryEngine sending request, this.libraryStarted: true
prisma:client:libraryEngine sending request, this.libraryStarted: true
prisma:client:libraryEngine sending request, this.libraryStarted: true
prisma:client:libraryEngine sending request, this.libraryStarted: true
prisma:client:libraryEngine sending request, this.libraryStarted: true
prisma:client:libraryEngine sending request, this.libraryStarted: true
prisma:client:libraryEngine sending request, this.libraryStarted: true
prisma:client:libraryEngine sending request, this.libraryStarted: true
prisma:client:libraryEngine sending request, this.libraryStarted: true
prisma:client:libraryEngine sending request, this.libraryStarted: true
prisma:client:libraryEngine sending request, this.libraryStarted: true
prisma:client:libraryEngine sending request, this.libraryStarted: true
prisma:client:libraryEngine sending request, this.libraryStarted: true
prisma:client:libraryEngine sending request, this.libraryStarted: true
prisma:client:libraryEngine sending request, this.libraryStarted: true
prisma:client:libraryEngine sending request, this.libraryStarted: true
prisma:client:libraryEngine sending request, this.libraryStarted: true
prisma:client:libraryEngine sending request, this.libraryStarted: true
prisma:client:libraryEngine sending request, this.libraryStarted: true
prisma:client:libraryEngine sending request, this.libraryStarted: true
prisma:client:libraryEngine sending request, this.libraryStarted: true
prisma:client:libraryEngine sending request, this.libraryStarted: true
prisma:client:libraryEngine sending request, this.libraryStarted: true
prisma:client prisma.queryRaw(
      select name, values 
      from (
        with parameter as (
          (select "projectId", name, value from "ParameterText")
          union
          (select "projectId", name, value from "ParameterCommit")
          union
          (select "projectId", name, value::text from "ParameterTimestamp")
          union
          (select "projectId", name, value::text from "ParameterNumber")
        )
        select name, array_agg(distinct value) as "values"
        from parameter
        where "projectId" = $1 and name != $2
        group by name
      ) x
      where array_length(values, 1) > 1
      order by name
    , [[1,""]])
prisma:client Prisma Client call:
prisma:client:libraryEngine sending request, this.libraryStarted: true
prisma:client prisma.queryRaw(
    (
      select distinct "ParameterText".name, 'TEXT' as "type"
      from "ParameterText"
      where "projectId" = $1
    )
    union
    (
      select distinct "ParameterTimestamp".name, 'TIMESTAMP' as "type"
      from "ParameterTimestamp"
      where "projectId" = $1
    )
    union
    (
      select distinct "ParameterNumber".name, 'NUMBER' as "type"
      from "ParameterNumber"
      where "projectId" = $1
    )
    union
    (
      select distinct "ParameterCommit".name, 'COMMIT' as "type"
      from "ParameterCommit"
      where "projectId" = $1
    )
    order by name, [[1]])
prisma:client Prisma Client call:
prisma:client:libraryEngine sending request, this.libraryStarted: true
prisma:client:libraryEngine sending request, this.libraryStarted: true
prisma:client:request_handler Error: Your raw query had an incorrect number of parameters. Expected: `2`, actual: `1`.
    at prismaGraphQLToJSError (/Users/chris/Workspace/api/node_modules/@prisma/client/runtime/index.js:33922:12)
    at Object.request (/Users/chris/Workspace/api/node_modules/@prisma/client/runtime/index.js:35748:17)
    at async Object.request (/Users/chris/Workspace/api/node_modules/@prisma/client/runtime/index.js:39788:24)
    at async Proxy._request (/Users/chris/Workspace/api/node_modules/@prisma/client/runtime/index.js:40649:18)
prisma:client:request_handler Error: called `Result::unwrap()` on an `Err` value: Any { .. }
    at prismaGraphQLToJSError (/Users/chris/Workspace/api/node_modules/@prisma/client/runtime/index.js:33924:10)
    at Object.request (/Users/chris/Workspace/api/node_modules/@prisma/client/runtime/index.js:35748:17)
    at async Object.request (/Users/chris/Workspace/api/node_modules/@prisma/client/runtime/index.js:39788:24)
    at async Proxy._request (/Users/chris/Workspace/api/node_modules/@prisma/client/runtime/index.js:40649:18)

%23%23 Client Snippet

  const user = await db.user.findUnique({
    where: { email },
    include: {
      githubUser: true,
      teamMemberships: {
        include: {
          team: {
            include: {
              projects: true,
            },
          },
        },
      },
    },
  })

%23%23 Schema

generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["interactiveTransactions"]
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

enum Aggregation {
  AVERAGE
  SUM
  MIN
  MAX
  COUNT
}

model Benchmark {
  id                  Int                  @id() @default(autoincrement())
  projectId           Int
  uploadedFromId      Int
  uploadedAt          DateTime             @db.Timestamptz(6)
  project             Project              @relation(fields: [projectId], references: [id])
  user                User                 @relation(fields: [uploadedFromId], references: [id])
  metrics             Metric[]
  parametersCommit    ParameterCommit[]
  parametersNumber    ParameterNumber[]
  parametersText      ParameterText[]
  parametersTimestamp ParameterTimestamp[]
}

model GithubInstallation {
  id                   Int                  @id()
  suspended            Boolean
  permissions          Json                 @db.Json
  accessToken          String               @db.VarChar
  accessTokenExpiresAt DateTime             @db.Timestamp(6)
  installedById        Int
  installedInId        Int                  @unique
  repositories         GithubRepository[]
  installedBy          User                 @relation(fields: [installedById], references: [id])
  installedIn          GithubIdentity       @relation(fields: [installedInId], references: [id])
  GithubOrganization   GithubOrganization[]
  GithubUser           GithubUser[]
}

model GithubIdentity {
  id                Int                 @id()
  user              GithubUser?
  organization      GithubOrganization?
  ownedRepositories GithubRepository[]
  ownedInstallation GithubInstallation?
}

model GithubOrganization {
  id                 Int                 @id()
  login              String              @db.VarChar
  installationId     Int?                @unique()
  identity           GithubIdentity      @relation(fields: [id], references: [id])
  githubInstallation GithubInstallation? @relation(fields: [installationId], references: [id])
}

model GithubRepository {
  id         Int                        @id()
  name       String                     @db.VarChar
  ownerId    Int
  isPrivate  Boolean
  visibility GithubRepositoryVisibility
  owner      GithubIdentity             @relation(fields: [ownerId], references: [id])
  project    Project?

  installedWith        GithubInstallation? @relation(fields: [githubInstallationId], references: [id])
  githubInstallationId Int?
  @@index([ownerId, name])
}

enum GithubRepositoryVisibility {
  PUBLIC
  PRIVATE
  INTERNAL
}

model GithubUser {
  id                 Int                 @id()
  login              String              @unique() @db.VarChar
  accessToken        String?
  tokenType          String?
  installationId     Int?                @unique()
  githubInstallation GithubInstallation? @relation(fields: [installationId], references: [id])
  identity           GithubIdentity      @relation(fields: [id], references: [id])
  user               User?
}

model Job {
  id         Int       @id() @default(autoincrement())
  created    DateTime  @db.Timestamptz(6)
  status     JobStatus
  projectId  Int
  commitHash String    @db.VarChar
  ref        String    @db.VarChar
  project    Project   @relation(fields: [projectId], references: [id])

  @@index([created])
}

enum JobStatus {
  CREATED
  PUBLIC
  FINISHED
  FAILED
}

model Line2dWidget {
  id            Int                @id() @unique()
  created       DateTime           @db.Timestamp(6)
  parameterName String             @db.VarChar
  metricName    String             @db.VarChar
  parameterType ParameterType
  properties    Json               @db.Json
  widget        Widget             @relation(fields: [id], references: [id])
  lines         Line2dWidgetLine[]
}

model Line2dWidgetLine {
  id              Int          @id() @default(autoincrement())
  name            String       @db.VarChar
  aggregation     Aggregation  @default(AVERAGE)
  fixedParameters Json         @db.Json
  widgetId        Int
  widget          Line2dWidget @relation(fields: [widgetId], references: [id])
}

model Metric {
  benchmarkId Int
  projectId   Int
  name        String    @db.VarChar
  value       Decimal   @db.Decimal
  benchmark   Benchmark @relation(fields: [benchmarkId], references: [id])
  project     Project   @relation(fields: [projectId], references: [id])

  @@id([benchmarkId, name])
}

model ParameterCommit {
  benchmarkId Int
  projectId   Int
  name        String    @db.VarChar
  required    Boolean
  value       String    @db.VarChar
  benchmark   Benchmark @relation(fields: [benchmarkId], references: [id])
  project     Project   @relation(fields: [projectId], references: [id])

  @@id([benchmarkId, name])
  @@index([projectId, name, value])
}

model ParameterNumber {
  benchmarkId Int
  projectId   Int
  name        String    @db.VarChar
  required    Boolean
  value       Decimal   @db.Decimal
  benchmark   Benchmark @relation(fields: [benchmarkId], references: [id])
  project     Project   @relation(fields: [projectId], references: [id])

  @@id([benchmarkId, name])
  @@index([projectId, name, value])
}

model ParameterText {
  benchmarkId Int
  projectId   Int
  name        String    @db.VarChar
  required    Boolean
  value       String    @db.VarChar
  benchmark   Benchmark @relation(fields: [benchmarkId], references: [id])
  project     Project   @relation(fields: [projectId], references: [id])

  @@id([benchmarkId, name])
  @@index([projectId, name, value])
}

model ParameterTimestamp {
  benchmarkId Int
  projectId   Int
  name        String    @db.VarChar
  required    Boolean
  value       DateTime  @db.Timestamp(6)
  benchmark   Benchmark @relation(fields: [benchmarkId], references: [id])
  project     Project   @relation(fields: [projectId], references: [id])

  @@id([benchmarkId, name])
  @@index([projectId, name, value])
}

enum ParameterType {
  COMMIT
  NUMBER
  TEXT
  TIMESTAMP
}

model PersonalAccessToken {
  id          Int    @id() @default(autoincrement())
  accessToken String @unique() @db.VarChar
  userId      Int
  name        String @db.VarChar
  user        User   @relation(fields: [userId], references: [id])

  @@unique([userId, name])
}

model Project {
  id                      Int                  @id() @default(autoincrement())
  name                    String               @db.VarChar
  description             String               @db.VarChar
  createdAt               DateTime             @db.Timestamptz(6)
  lastBenchmarkUploadedAt DateTime?            @db.Timestamptz(6)
  repositoryId            Int?                 @unique()
  teamId                  Int?
  createdFromId           Int
  user                    User                 @relation(fields: [createdFromId], references: [id])
  githubRepository        GithubRepository?    @relation(fields: [repositoryId], references: [id])
  team                    Team?                @relation(fields: [teamId], references: [id])
  benchmarks              Benchmark[]
  jobs                    Job[]
  metrics                 Metric[]
  parametersCommit        ParameterCommit[]
  parametersNumber        ParameterNumber[]
  parametersText          ParameterText[]
  parametersTimestamp     ParameterTimestamp[]
  widgets                 Widget[]
}

model Runner {
  id          Int      @id() @default(autoincrement())
  accessToken String   @unique() @db.VarChar
  name        String   @db.VarChar
  lastPing    DateTime @db.Timestamptz(6)
  teamId      Int
  team        Team     @relation(fields: [teamId], references: [id])
}

model Team {
  id              Int              @id() @default(autoincrement())
  name            String           @unique() @db.VarChar
  description     String           @db.VarChar
  projects        Project[]
  runners         Runner[]
  teamMemberships TeamMembership[]
}

model TeamMembership {
  id     Int  @id() @default(autoincrement())
  userId Int
  teamId Int
  team   Team @relation(fields: [teamId], references: [id])
  user   User @relation(fields: [userId], references: [id])

  @@unique([userId, teamId])
}

model User {
  id                    Int                   @id() @default(autoincrement())
  email                 String                @unique() @db.VarChar
  passwordHash          String                @db.VarChar
  emailConfirmationCode String                @db.VarChar
  emailConfirmed        Boolean
  githubConnectSecret   String                @db.VarChar
  githubUserId          Int?                  @unique()
  githubUser            GithubUser?           @relation(fields: [githubUserId], references: [id])
  benchmark             Benchmark[]
  personalAccessTokens  PersonalAccessToken[]
  project               Project[]
  teamMemberships       TeamMembership[]
  GithubInstallation    GithubInstallation[]
}

model Widget {
  id           Int           @id() @default(autoincrement())
  projectId    Int
  widgetType   WidgetType
  project      Project       @relation(fields: [projectId], references: [id])
  line2dWidget Line2dWidget?
}

enum WidgetType {
  LINE2D
}

%23%23 Prisma Engine Query

{"X":{}}
@janpio janpio added team/client Issue for team Client. bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. kind/bug A reported bug. labels Apr 4, 2022
@dpetrick dpetrick added topic: raw $queryRaw(Unsafe) and $executeRaw(Unsafe): https://www.prisma.io/docs/concepts/components/prisma-cli priority/unknown labels Apr 8, 2022
@Weakky
Copy link
Member

Weakky commented Apr 25, 2022

Hey @ChristianMoesl,

Would you mind sharing more details with regards to your issue? A small reproduction would be nice or at least a Prisma Schema that we could use to reproduce your issue ourselves.

Your client snippet shows a findUnique call but the error shows it's related to a $queryRaw call.

prisma:client prisma.queryRaw(
    (
      select distinct "ParameterText".name, 'TEXT' as "type"
      from "ParameterText"
      where "projectId" = $1
    )
    union
    (
      select distinct "ParameterTimestamp".name, 'TIMESTAMP' as "type"
      from "ParameterTimestamp"
      where "projectId" = $1
    )
    union
    (
      select distinct "ParameterNumber".name, 'NUMBER' as "type"
      from "ParameterNumber"
      where "projectId" = $1
    )
    union
    (
      select distinct "ParameterCommit".name, 'COMMIT' as "type"
      from "ParameterCommit"
      where "projectId" = $1
    )
    order by name, [[1]])
prisma:client Prisma Client call:
prisma:client:libraryEngine sending request, this.libraryStarted: true
prisma:client:libraryEngine sending request, this.libraryStarted: true
prisma:client:request_handler Error: Your raw query had an incorrect number of parameters. Expected: `2`, actual: `1`.

Thank you! 🙏

@ChristianMoesl
Copy link
Author

Hey @Weakky ,
yeah I can provide more information probably by tomorrow. Indeed you are right, I think the error occurred, because we called queryRaw with an incorrect number of arguments. What is the current behaviour of the engine for this case? I think it should not die here, right?

@Weakky
Copy link
Member

Weakky commented Apr 27, 2022

I think it should not die here, right?

It shouldn't die indeed which is why your reproduction is valuable 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. kind/bug A reported bug. team/client Issue for team Client. topic: raw $queryRaw(Unsafe) and $executeRaw(Unsafe): https://www.prisma.io/docs/concepts/components/prisma-cli
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants