question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MySQL: Expected parent IDs to be set when ordering by parent ID.

See original GitHub issue

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

Versions

Name Version
Node v16.15.0
OS rhel-openssl-1.0.x
Prisma Client 4.0.0
Query Engine da41d2bb3406da22087b849f0e911199ba4fbf11
Database mysql

Logs

prisma:tryLoadEnv Environment variables not found at null
prisma:tryLoadEnv Environment variables not found at undefined
prisma:tryLoadEnv No Environment variables loaded
prisma:tryLoadEnv Environment variables not found at null
prisma:tryLoadEnv Environment variables not found at undefined
prisma:tryLoadEnv No Environment variables loaded
prisma:client dirname /var/task/node_modules/.prisma/client
prisma:client relativePath ../../../prisma
prisma:client cwd /var/task/node_modules/.prisma/client
prisma:client clientVersion: 4.0.0
prisma:client clientEngineType: library
prisma:client:libraryEngine internalSetup
prisma:client:libraryEngine:loader Searching for Query Engine Library in /var/task/node_modules/.prisma/client
prisma:client:libraryEngine:loader loadEngine using /var/task/node_modules/.prisma/client/libquery_engine-rhel-openssl-1.0.x.so.node
prisma:client:libraryEngine sending request, this.libraryStarted: false
prisma:client:libraryEngine library starting
prisma:client:libraryEngine library started
prisma:client:request_handler {"clientVersion":"4.0.0"}
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:request_handler {"clientVersion":"4.0.0"}
prisma:client:libraryEngine sending request, this.libraryStarted: true
prisma:client:request_handler {"clientVersion":"4.0.0"}
prisma:client:libraryEngine sending request, this.libraryStarted: true
prisma:client:request_handler {"clientVersion":"4.0.0"}
prisma:client:libraryEngine sending request, this.libraryStarted: true

Client Snippet

prismaClient.user
  .findUnique({
    where: {
      email: input?.email,
    },
  })
  .words({
    select: {
      id: true,
      score: true,
      master: true,
      wordData: true,
    },
  });

Schema

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

datasource db {
  provider             = "mysql"
  url                  = env("DATABASE_URL")
  referentialIntegrity = "prisma"
}

model Account {
  id                String   @id @default(cuid())
  userId            String   @unique
  type              String
  provider          String
  providerAccountId String
  refresh_token     String?  @db.LongText
  access_token      String?  @db.LongText
  expires_at        Int?
  token_type        String?
  scope             String?
  id_token          String?  @db.Text
  session_state     String?
  createdAt         DateTime @default(now())
  updatedAt         DateTime @updatedAt
  isAdmin           Boolean  @default(false)
  isActive          Boolean  @default(true)
  isDeleted         Boolean  @default(false)
  user              User     @relation(fields: [userId], references: [id], onDelete: Cascade)

  @@unique([provider, providerAccountId])
}

model User {
  id            String    @id @default(cuid())
  name          String?
  email         String?   @unique
  password      String?   @unique
  emailVerified DateTime?
  image         String?
  accounts      Account[]
  sessions      Session[]
  words         Word[]
}

model Session {
  id           String   @id @default(cuid())
  sessionToken String   @db.LongText
  userId       String   @unique
  expires      DateTime
  user         User?    @relation(fields: [userId], references: [id], onDelete: Cascade)
}

model VerificationToken {
  identifier String
  token      String   @unique
  expires    DateTime

  @@unique([identifier, token])
}

model Word {
  id        String    @id @default(cuid())
  score     Int       @default(0)
  master    Boolean   @default(false)
  wordData  WordData? @relation(fields: [word], references: [searchingWord])
  word      String    @unique
  user      User?     @relation(fields: [userId], references: [id])
  userId    String?
  createdAt DateTime  @default(now())
  updatedAt DateTime  @updatedAt
}

model WordData {
  id              String   @id @default(cuid())
  createdAt       DateTime @default(now())
  updatedAt       DateTime @updatedAt
  searchingWord   String   @unique
  searchingEngine String
  translations    Json?
  userWords       Word[]
}

Prisma Engine Query

Query:
{
  "modelName": "WordData",
  "operation": "findMany",
  "args": {
    "take": 100,
    "skip": 0,
    "select": {
      "id": true,
      "createdAt": true,
      "updatedAt": true,
      "searchingWord": true,
      "searchingEngine": true,
      "translations": true,
      "userWords": true
    }
  }
}

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
hampuskraftcommented, Oct 6, 2022

@jkomyno Thanks. Unfortunately, changing the database collation is not an option in production since everything relies on case insensitivity. I ran a query that fixed the inconsistent results across our database, which does the trick for now. But yes, I can confirm that a “bin” collation doesn’t have this issue in development.

1reaction
gabrielbusarellocommented, Aug 1, 2022

Hi guys, Maybe I can bring some new information to this case. I’m facing this problem too, and I think I know de causes, and I want to know if it is the cause. I have this model:

model BudgetApprover {
  id                 String              @id @default(cuid())
  type               Int
  userId             String
  user               User                @relation(fields: [userId], references: [id], onDelete: NoAction, onUpdate: NoAction)
  accountingAccounts AccountingAccount[]
  costCenters        CostCenter[]
  accountingItems    AccountingItem[]
  classValues        ClassValue[]

  @@unique([ type, userId ])
}

// The model from those four fields are the same as this (Are four different models in my schema):

model AccountingAccount | costCenters | accountingItems | classValues {
  code            String           @id @db.VarChar(20)
  name            String           @db.VarChar(50)
  budgets         Budget[]
  budgetApprovers BudgetApprover[]
}

I have two endpoints that are requested in one page at the same moment, and runs this same query. I read in the docs, that Prisma batches the findUnique method when requested in a tick.

return this.prisma.budgetApprover.findUnique({
        where: { type_userId: { userId, type: BudgetApproverType.CORPORATIVE_LEVEL } }
});

In my codes, I use async/await, and when this executes, the first request ran and I get an OK and the second one returns:

Invalid `prisma.budgetApprover.findUnique()` invocation:
4|rodalog-staging  |   PANIC: Expected parent IDs to be set when ordering by parent ID. in query-engine/core/src/interpreter/query_interpreters/inmemory_record_processor.rs:71:18

I’m facing this problem too, and not just in prisma studio. I simulate this on studio, by querying accountingAccount the error is below:

Message: Error in Prisma Client request: 


Invalid `prisma.accountingAccount.findMany()` invocation:


  Expected parent IDs to be set when ordering by parent ID.
  
Query:
prisma.accountingAccount.findMany({
  where: {
    AND: [
    ]
  },
  take: 100,
  skip: 0,
  select: {
    code: true,
    name: true,
    budgets: true,
    budgetApprovers: true,
  }
})

Maybe do I have to use Promise.then to this cases? I can put the codes that I developed, if you want. This are the versions that I’m using:

prisma                  : 3.5.0
@prisma/client          : 3.5.0
Current platform        : windows
Query Engine (Node-API) : libquery-engine 78a5df6def6943431f4c022e1428dbc3e833cf8e (at node_modules\@prisma\engines\query_engine-windows.dll.node)
Migration Engine        : migration-engine-cli 78a5df6def6943431f4c022e1428dbc3e833cf8e (at node_modules\@prisma\engines\migration-engine-windows.exe)
Introspection Engine    : introspection-core 78a5df6def6943431f4c022e1428dbc3e833cf8e (at node_modules\@prisma\engines\introspection-engine-windows.exe)
Format Binary           : prisma-fmt 78a5df6def6943431f4c022e1428dbc3e833cf8e (at node_modules\@prisma\engines\prisma-fmt-windows.exe)
Default Engines Hash    : 78a5df6def6943431f4c022e1428dbc3e833cf8e
Studio                  : 0.439.0
Read more comments on GitHub >

github_iconTop Results From Across the Web

MySQL: PANIC: Expected parent IDs to be set when ordering ...
Hi Prisma Team! My Prisma Client just crashed. This is the report: Versions Name Version Node v12.22.7 OS debian-openssl-1.1.x Prisma Client 3.1.1 Query ......
Read more >
how to get all children by multiple parent ids using IN() clause
I'm trying to get all children records by their parent IDs(multiple) using IN clause but its return only children belong to first parent...
Read more >
Create parent node and parent id [closed]
I have a table which contains id , nodeid , nodevalue , and nodelevel columns. Now I want to create new temp column...
Read more >
MySQL 8.0 Reference Manual :: 13.2.17 UPDATE Statement
To avoid this problem, add an ORDER BY clause to cause the rows with larger id values to be updated before those with...
Read more >
Prisma Client API (Reference)
AssertionError("Expected a valid parent ID to be present for nested update to-one case.") If the related record that you want to update does...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found