- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 125
 
Closed
Labels
Description
Error
Uncaught:
Error calling enhanced Prisma method `user.upsert`: result.merge is not a function
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.modelsare of typeZodObject, but it seems like any models that have model level validation on it along with polymorphic extensions of it are of typeZodEffects. (in img below, the User model is derived from the Entity model)

 
Testing
- Problem is resolved if I remove any 
@@validatefunctions 
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