Prisma client not marking `Json` property as `null`
Open
Nobody has claimed this yet.
bug/1-unconfirmed
kind/bug
tech/typescript
topic: client types
topic: Json
topic: null vs undefined
- Dominant language
- TypeScript
- Stars
- 47.6k
- Forks
- 2.5k
- Avg merge
- 21h 59m
- Merged PRs (30d)
- 95
Description
Bug description
I am using Prisma version 3.8.1. Prisma client does not mark the User.oauthData property as nullable in TS. Can someone help? Prisma schema and generated SQL files below:
How to reproduce
Run prisma generate with attached schema file on MacOS (Postgres)
Expected behavior
No response
Prisma information
Schema:
generator client {
provider = "prisma-client-js"
binaryTargets = ["native", "rhel-openssl-1.0.x"]
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model Account {
id BigInt @id
createdAt DateTime @db.Timestamptz(3) @default(now())
updatedAt DateTime @db.Timestamptz(3) @updatedAt
name String
users User[]
}
model User {
id BigInt @id
createdAt DateTime @db.Timestamptz(3) @default(now())
updatedAt DateTime @db.Timestamptz(3) @updatedAt
accountId BigInt
account Account @relation(fields: [accountId], references: [id])
fullName String
email String
oauthData Json?
}
SQL:
-- CreateTable
CREATE TABLE "Account" (
"id" BIGINT NOT NULL,
"createdAt" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMPTZ(3) NOT NULL,
"name" TEXT NOT NULL,
CONSTRAINT "Account_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "User" (
"id" BIGINT NOT NULL,
"createdAt" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMPTZ(3) NOT NULL,
"accountId" BIGINT NOT NULL,
"fullName" TEXT NOT NULL,
"email" TEXT NOT NULL,
"oauthData" JSONB,
CONSTRAINT "User_pkey" PRIMARY KEY ("id")
);
-- AddForeignKey
ALTER TABLE "User" ADD CONSTRAINT "User_accountId_fkey" FOREIGN KEY ("accountId") REFERENCES "Account"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
Environment & setup
- OS: Mac OS
- Database: PostgreSQL
- Node.js version: 16.13.1
Prisma Version
prisma : 3.8.1
@prisma/client : 3.8.1
Current platform : darwin
Query Engine (Node-API) : libquery-engine 34df67547cf5598f5a6cd3eb45f14ee70c3fb86f (at node_modules/@prisma/engines/libquery_engine-darwin.dylib.node)
Migration Engine : migration-engine-cli 34df67547cf5598f5a6cd3eb45f14ee70c3fb86f (at node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine : introspection-core 34df67547cf5598f5a6cd3eb45f14ee70c3fb86f (at node_modules/@prisma/engines/introspection-engine-darwin)
Format Binary : prisma-fmt 34df67547cf5598f5a6cd3eb45f14ee70c3fb86f (at node_modules/@prisma/engines/prisma-fmt-darwin)
Default Engines Hash : 34df67547cf5598f5a6cd3eb45f14ee70c3fb86f
Studio : 0.452.0
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Prisma schema shown in the issue and run prisma generate against the PostgreSQL model, then inspect the generated TypeScript client declaration for User.oauthData. Done means the generated type reflects the nullable Json? field, with the behavior verified against this reproduction schema.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- node.js, postgresql, typescript
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100