Skip to content

JSON fields map to incorrect typedef in enhanced Prisma client #1991

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

Closed
diesal11 opened this issue Feb 20, 2025 · 1 comment
Closed

JSON fields map to incorrect typedef in enhanced Prisma client #1991

diesal11 opened this issue Feb 20, 2025 · 1 comment

Comments

@diesal11
Copy link
Contributor

Description and expected behavior
Given the following model schema:

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

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

type FooMetadata {
    isLocked Boolean
}

type FooOptionMetadata {
    color String
}

model Foo {
    id   String      @id @db.Uuid @default(uuid())
    meta FooMetadata @json
}

model FooOption {
    id   String            @id @db.Uuid @default(uuid())
    meta FooOptionMetadata @json
}

zenstack generate will create an enhanced PrismaClient which incorrectly maps the type of FooOption.meta for prisma input types to FooMetadata instead of FooOptionMetadata. The result payload type correctly maps meta to FooOptionMeta.

Screenshots

Image Image

Environment (please complete the following information):

  • ZenStack version: 2.11.6
  • Prisma version: 6.3.1
  • Database type: Postgresql

Additional context

Interestingly, renaming FooOption/FooOptionMetadata to Bar/BarMetadata seems to resolve the issue. So at first glance it seems something is breaking when the string Option is used?

I'd be happy to spend some more time investigating this issue, but would appreciate any advice the team has.

Repo which reproduces the bug:
https://github.com./diesal11/zenstack-json-type-bug

@diesal11 diesal11 changed the title JSON fields mapped to incorrect typedef in enhanced Prisma client JSON fields map to incorrect typedef in enhanced Prisma client Feb 20, 2025
@ymc9
Copy link
Member

ymc9 commented Feb 21, 2025

Thanks for filing this @diesal11 . Some pattern matching code messed up JSON type processing. I'm making a fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants