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

console.log(prisma) freezes and does not return #19648

Closed
fohanist opened this issue Jun 7, 2023 · 5 comments
Closed

console.log(prisma) freezes and does not return #19648

fohanist opened this issue Jun 7, 2023 · 5 comments
Labels
bug/2-confirmed Bug has been reproduced and confirmed. domain/client Issue in the "Client" domain: Prisma Client, Prisma Studio etc. kind/bug A reported bug. tech/typescript Issue for tech TypeScript. topic: logging topic: windows

Comments

@fohanist
Copy link

fohanist commented Jun 7, 2023

Bug description

Set prisma in the root model. Subsequently, the prisma is received from the sole model and the user model is created through the proxy object. When you try to output an instance of the user model, the console recursively invokes an object and freezes the terminal. I'm very curious about the reason.

image

How to reproduce

$ npm init -y
$ npm install typescript ts-node prisma

...create prisma schema
...user create success

Problem code run

import { PrismaClient, User as UserSchema } from "@prisma/client";

class RootModel {
  public prisma: PrismaClient;

  constructor() {
    this.prisma = new PrismaClient();
  }

  public proxyWrapper<T>(object: T | null) {
    const innerObj = object || {};
    return new Proxy(innerObj as any, {
      get: (target, prop) => {
        return target[prop];
      },
      set: (target, prop, value) => {
        target[prop] = value;
        return true;
      },
    });
  }
}

class User extends RootModel {
  public data: UserSchema | {} = {};

  constructor(userData: UserSchema | null = null) {
    super();
    this.data = this.proxyWrapper<UserSchema>(userData);
  }
}

async function main() {
  const user = new User();
  console.log(user);
}

main();

Expected behavior

I wanted to use it like the active record I use on Ruby on Rails. I thought I could create a user model object and then access user data through a proxy object. Wanted to avoid writing all the user properties to model objects.

Prisma information

// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

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

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

model User {
  id    Int     @id @default(autoincrement())
  email String  @unique
  name  String?
  posts Post[]
}

model Post {
  id        Int     @id @default(autoincrement())
  title     String
  content   String?
  published Boolean @default(false)
  author    User    @relation(fields: [authorId], references: [id])
  authorId  Int
}

Environment & setup

  • OS: windows wsl2
  • Database: sqlite, postgresql
  • Node.js version: v18.16

Prisma Version

"@prisma/client": "^4.15.0",
"prisma": "^4.15.0",
"ts-node": "^10.9.1",
"typescript": "^5.1.3"
@fohanist fohanist added the kind/bug A reported bug. label Jun 7, 2023
@petradonka petradonka added domain/client Issue in the "Client" domain: Prisma Client, Prisma Studio etc. bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. topic: windows labels Jun 7, 2023
@Weakky Weakky added bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. and removed bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. labels Jul 13, 2023
@janpio janpio added topic: logging tech/typescript Issue for tech TypeScript. labels Jul 13, 2023
@aqrln
Copy link
Member

aqrln commented Aug 16, 2023

Minimal reproduction:

const prisma = new PrismaClient()
console.log(prisma)

On Prisma 4.15.0 (the version from the report) this prints 152 MiB of output and exits, on latest Prisma from main this freezes indefinitely.

A workaround for you @fohanist is to either make prisma a private field (as in a real private field in JS, #prisma, not TypeScript's private prisma), or implement util.inspect.custom in a way that would skip prisma.

@aqrln aqrln added bug/2-confirmed Bug has been reproduced and confirmed. and removed bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. labels Aug 16, 2023
@aqrln aqrln changed the title prisma with proxy object occur console.log(prisma) freezes and does not return Aug 16, 2023
@aqrln
Copy link
Member

aqrln commented Aug 16, 2023

(and we should definitely implement Symbol.for('nodejs.util.inspect.custom') on PrismaClient on our side)

@janpio
Copy link
Member

janpio commented Aug 22, 2023

Duplicate: #18292

@janpio
Copy link
Member

janpio commented Aug 22, 2023

Can we close this one maybe @aqrln @fohanist and move all the additional information over to #18292?

@aqrln
Copy link
Member

aqrln commented Aug 22, 2023

Closing in favor of #18292

@aqrln aqrln closed this as not planned Won't fix, can't repro, duplicate, stale Aug 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/2-confirmed Bug has been reproduced and confirmed. domain/client Issue in the "Client" domain: Prisma Client, Prisma Studio etc. kind/bug A reported bug. tech/typescript Issue for tech TypeScript. topic: logging topic: windows
Projects
None yet
Development

No branches or pull requests

5 participants