Skip to content

[Bug?] @password Attribute Function Calling Undefined Zod Function During Update, Upsert #2000

Closed
@breagan1983

Description

@breagan1983

Error

Uncaught:
Error calling enhanced Prisma method `user.upsert`: result.merge is not a function

policy-utils.ts:1387

Description and expected behavior

  • ✅ Works Fine
    • db.user.create({data: {username: 'admin', password: 'abc12345'}})
  • ❌ Causes Error
    • db.user.update({where: {username: 'admin'}, data: {password: 'abc123456789123'}})
    • db.user.upsert({where: {username: 'admin'}, update: {username: 'admin2'}, create: {username: 'admin', password: 'abc123456789'}})

Additional Context*

  • I think it relates to issues talked about in @zenstackhq/zenstack#676 and @colinhacks/zod:2646
  • Some of the schemas in this.zodSchemas.models are of type ZodObject, but it seems like any models that have model level validation on it along with polymorphic extensions of it are of type ZodEffects . (in img below, the User model is derived from the Entity model)
    Image

Testing

  • Problem is resolved if I remove any @@validate functions

ZModel
(sidenote: please don't be alarmed by the overly permissive @@allow() s, still in early development)

abstract model Base {
    id              String          @id  @default(uuid())    @deny('update', true)
    createdAt       DateTime        @default(now())          @deny('update', true)
    updatedAt       DateTime        @updatedAt               @deny('update', true)
    active          Boolean         @default(false)
    published       Boolean         @default(true)           
    deleted         Boolean         @default(false)
    startDate       DateTime?
    endDate         DateTime?

    @@allow('create', true)
    @@allow('read', true)
    @@allow('update', true)
}

enum EntityType {
    User
    Alias
    Group
    Service
    Device
    Organization
    Guest
}

model Entity extends Base {
    entityType      EntityType
    name            String?                 @unique
    members         Entity[]                @relation("members")
    memberOf        Entity[]                @relation("members")
    @@delegate(entityType)


    @@allow('create', true)
    @@allow('read', true)
    @@allow('update', true)
    @@validate(!active || (active && name != null), "Active Entities Must Have A Name")
}

model User extends Entity {
    profile         Json?               
    username        String                  @unique 
    password        String                  @password

    @@allow('create', true)
    @@allow('read', true)
    @@allow('update', true)
}

Environment (please complete the following information):

  • ZenStack version: 2.11.6
  • Prisma version: 6.3.1
  • Database type: SQLite
  • Zod Version : 3.24.2

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions