prisma / prisma-client-js

Type-safe database client for TypeScript & Node.js (ORM replacement)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PANIC: 1 Invalid findMany() after nested write

ddgond opened this issue · comments

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

Versions

Name Version
Node v10.21.0
OS darwin
Prisma Client 2.12.1

Logs

  prisma-client { clientVersion: '2.12.1' }  
  plusX Execution permissions of /Users/dangond/Documents/coding/blaseball-lite/server/node_modules/.prisma/client/query-engine-darwin are fine  
  plusX Execution permissions of /Users/dangond/Documents/coding/blaseball-lite/server/node_modules/.prisma/client/query-engine-darwin are fine  

Schema

Here's my current schema

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

generator client {
  provider = "prisma-client-js"
}

model League {
  id String @id
  name String @unique
  divisions Division[]
}

model Division {
  id String @id
  name String
  teams Team[]
  league League @relation(fields: [leagueId], references: [id])
  leagueId String
}

model Game {
  id String @id
  teams Team[]
}

model Team {
  id String @id
  name String @unique
  players Player[]
  games Game[]
  divisions Division[]
}

model Player {
  id String @id
  name String
  team Team[]
}

Code I'm attempting to run

I've split this off into its own script file to attempt to narrow down the issue

const allTeams = await prisma.team.findMany({
  include: {
    games: true
  }
});
console.log(allTeams);

Specific error I'm getting

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


  PANIC: 1

This is a non-recoverable error which probably happens when the Prisma Query Engine has a panic.

Current Hypothesis / How games are created

Here's a snippet for how I'm adding games, which works by connecting to two existing teams and succeeds at returning the team data. However, attempting to open the Team table in Prisma Studio after adding a game causes it to Panic with the same issue. My guess is somehow the process of creating the games corrupts the teams table in the db but doesn't cause issues until you try to get games from teams. I've tried dropping the DB and re-running the migration, but the same issue persists.

prisma.game.create({
  data: {
    id: generateId(),
    teams: {
      connect: [{ id: "id1" },{ id: "id2" }]
    }
  },
  include: {
    teams: true
  }
});

After a bit more testing with creating games directly on Prisma Studio, the issue only arises if a game has multiple teams. If I create a game with a single team, everything works fine. If I then add another team to that game, the Team table panics.

Looking at the resulting db directly in postgres, it also seems like the _GameToTeam table gets populated just fine, and the Game and Team tables look as expected, so there's something very strange going on here

Interestingly, this problem went away after adding more fields to the Game table.

Hey @ddgond

I tried a reproduction and wasn't able to reproduce this. So I am going to close this as problem also seemed to be fixed at your end.