Skip to content

adding plugin @core/enhancer breaks validation checks for @core/zod plugin #1562

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
tmax22 opened this issue Jul 7, 2024 · 1 comment
Closed
Milestone

Comments

@tmax22
Copy link

tmax22 commented Jul 7, 2024

I have no idea why, but adding plugin @core/enhancer breaks validation checks for @core/zod plugin

✅ Good

in the following schema, ^[a-zA-Z0-9_]{3,30}$ regex validation would correctly take place on User.name:

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

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

plugin hooks {
    provider = '@zenstackhq/tanstack-query'
    target = 'react'
    version = 'v5'
    output = 'src/hooks/generated'
}

plugin zod {
    provider = '@core/zod'
}

model User extends Base {
    name String @unique @regex('^[a-zA-Z0-9_]{3,30}$')

    @@allow('read', true)
}

image

❌ Bad

surprisingly enough, adding plugin enhancer plugin to the previous schema would result in @regex validation on User.name to be completely ignored:

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

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

plugin hooks {
    provider = '@zenstackhq/tanstack-query'
    target = 'react'
    version = 'v5'
    output = 'src/hooks/generated'
}

plugin zod {
    provider = '@core/zod'
}
plugin enhancer {
    provider = '@core/enhancer'
    generatePermissionChecker = true
}

abstract model Base {
    id        String   @id @default(uuid())
    createdAt DateTime @default(now())
    updatedAt DateTime @updatedAt()

    // require login
    @@allow('all', true)
}

model User extends Base {
    name String @unique @regex('^[a-zA-Z0-9_]{3,30}$')

    @@allow('read', true)
}

image

also tried to move around the enhancer plugin to check if its order related issue, it's not.

@ymc9
Copy link
Member

ymc9 commented Aug 2, 2024

Thanks for reporting this @tmax22 ! I've identified the issue and will make a fix in v2.4.

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