Skip to content

Error calling enhanced Prisma method with strictUndefinedCheck #1964

Open
@iksemot

Description

@iksemot

Description and expected behavior

Enhanced client errors on nested operations when strictUndefinedCheck is turned on.

Given data model:

generator client {
  provider = "prisma-client-js"
  previewFeatures = ["views", "strictUndefinedChecks"]

}

datasource db {
  provider = "sqlite"
  url      = "file:./dev.db"
}

view User {
  id    Int    @id
  orgId String
}

model Author {
  id    Int    @id @default(autoincrement())
  orgId String
  name  String
  posts Post[]

  @@unique([orgId, name])
  @@allow('all', auth().orgId == orgId)
}

model Post {
  id       Int     @id @default(autoincrement())
  orgId    String
  title    String
  author   Author  @relation(fields: [authorId], references: [id])
  authorId Int

  @@allow('all', auth().orgId == orgId)
}

Running following code:

import { PrismaClient } from '@prisma/client'
import { enhance } from '@zenstackhq/runtime'

;(async function main() {
    const _prisma = new PrismaClient({ log: ['info']  })
    const user = { id: 123, orgId: 'org' }
    const prisma = enhance(_prisma,
        { user },
        { logPrismaQuery: false }
    )
    
    const newauthor = await prisma.author.create({
        data: {
            name: `Foo ${Date.now()}`,
            orgId: user.orgId,
            posts: {
                createMany: { data: [{ title: 'Hello', orgId: user.orgId }] }
            }
        },
        include: { posts: true }
    })

    await prisma.author.update({
        where: { orgId_name: { orgId: 'org', name: newauthor.name } },
        data: {
            name: `Bar ${Date.now()}`,
            posts: { deleteMany: { id: { equals: newauthor.posts[0].id } } }
        },
    })
})()

Fails with:

prisma:info Starting a sqlite pool with 9 connections.
Error calling enhanced Prisma method `author.update`: 
Invalid `prisma.post.deleteMany()` invocation:

{
  where: {
    AND: [
      {
        id: {
          equals: 3
        },
        authorId: undefined
                  ~~~~~~~~~
      },
      {
        orgId: {
          equals: "org"
        }
      }
    ]
  }
}

Invalid value for argument `0`: explicitly `undefined` values are not allowed.
    at C:\Users\tomas\workspace\mindfuel\try-prisma-fastify\src\main.ts:23:25,
    at step (C:\Users\tomas\workspace\mindfuel\try-prisma-fastify\src\main.ts:33:23),
    at Object.next (C:\Users\tomas\workspace\mindfuel\try-prisma-fastify\src\main.ts:14:53),
    at fulfilled (C:\Users\tomas\workspace\mindfuel\try-prisma-fastify\src\main.ts:5:58) {
  name: 'PrismaClientValidationError',
  clientVersion: '6.1.0',
  internalStack: 'PrismaClientValidationError: \n' +
    'Invalid `prisma.post.deleteMany()` invocation:\n' +
    '\n' +
    '{\n' +
    '  where: {\n' +
    '    AND: [\n' +
    '      {\n' +
    '        id: {\n' +
    '          equals: 3\n' +
    '        },\n' +
    '        authorId: undefined\n' +
    '                  ~~~~~~~~~\n' +
    '      },\n' +
    '      {\n' +
    '        orgId: {\n' +
    '          equals: "org"\n' +
    '        }\n' +
    '      }\n' +
    '    ]\n' +
    '  }\n' +
    '}\n' +
    '\n' +
    'Invalid value for argument `0`: explicitly `undefined` values are not allowed.\n' +
    '    at wn (C:\\Users\\tomas\\workspace\\mindfuel\\try-prisma-fastify\\node_modules\\@prisma\\client\\runtime\\library.js:29:1363)\n' +
    '    at e.throwValidationError (C:\\Users\\tomas\\workspace\\mindfuel\\try-prisma-fastify\\node_modules\\@prisma\\client\\runtime\\library.js:29:10254)\n' +
    '    at da (C:\\Users\\tomas\\workspace\\mindfuel\\try-prisma-fastify\\node_modules\\@prisma\\client\\runtime\\library.js:29:9013)\n' +
    '    at pa (C:\\Users\\tomas\\workspace\\mindfuel\\try-prisma-fastify\\node_modules\\@prisma\\client\\runtime\\library.js:29:8487)\n' +
    '  }\n' +
    '}\n' +
    '\n' +
    'Invalid value for argument `0`: explicitly `undefined` values are not allowed.\n' +
    '    at wn (C:\\Users\\tomas\\workspace\\mindfuel\\try-prisma-fastify\\node_modules\\@prisma\\client\\runtime\\library.js:29:1363)\n' +
    '    at e.throwValidationError (C:\\Users\\tomas\\workspace\\mindfuel\\try-prisma-fastify\\node_modules\\@prisma\\client\\runtime\\library.js:29:10254)\n' +
    '    at da (C:\\Users\\tomas\\workspace\\mindfuel\\try-prisma-fastify\\node_modules\\@prisma\\client\\runtime\\library.js:29:9013)\n' +
    '    at pa (C:\\Users\\tomas\\workspace\\mindfuel\\try-prisma-fastify\\node_modules\\@prisma\\client\\runtime\\library.js:29:8487)\n' +
    '    at wn (C:\\Users\\tomas\\workspace\\mindfuel\\try-prisma-fastify\\node_modules\\@prisma\\client\\runtime\\library.js:29:1363)\n' +
    '    at e.throwValidationError (C:\\Users\\tomas\\workspace\\mindfuel\\try-prisma-fastify\\node_modules\\@prisma\\client\\runtime\\library.js:29:10254)\n' +
    '    at da (C:\\Users\\tomas\\workspace\\mindfuel\\try-prisma-fastify\\node_modules\\@prisma\\client\\runtime\\library.js:29:9013)\n' +
    '    at pa (C:\\Users\\tomas\\workspace\\mindfuel\\try-prisma-fastify\\node_modules\\@prisma\\client\\runtime\\library.js:29:8487)\n' +
    '    at da (C:\\Users\\tomas\\workspace\\mindfuel\\try-prisma-fastify\\node_modules\\@prisma\\client\\runtime\\library.js:29:9013)\n' +
    '    at pa (C:\\Users\\tomas\\workspace\\mindfuel\\try-prisma-fastify\\node_modules\\@prisma\\client\\runtime\\library.js:29:8487)\n' +
    '    at pa (C:\\Users\\tomas\\workspace\\mindfuel\\try-prisma-fastify\\node_modules\\@prisma\\client\\runtime\\library.js:29:8487)\n' +
    '    at md (C:\\Users\\tomas\\workspace\\mindfuel\\try-prisma-fastify\\node_modules\\@prisma\\client\\runtime\\library.js:29:9660)\n' +
    '    at pa (C:\\Users\\tomas\\workspace\\mindfuel\\try-prisma-fastify\\node_modules\\@prisma\\client\\runtime\\library.js:29:8076)\n' +
    '    at da (C:\\Users\\tomas\\workspace\\mindfuel\\try-prisma-fastify\\node_modules\\@prisma\\client\\runtime\\library.js:29:8956)\n' +
    '    at pa (C:\\Users\\tomas\\workspace\\mindfuel\\try-prisma-fastify\\node_modules\\@prisma\\client\\runtime\\library.js:29:8487)\n' +
    '    at da (C:\\Users\\tomas\\workspace\\mindfuel\\try-prisma-fastify\\node_modules\\@prisma\\client\\runtime\\library.js:29:8956)\n' +
    '    at mr (C:\\Users\\tomas\\workspace\\mindfuel\\try-prisma-fastify\\node_modules\\@prisma\\client\\runtime\\library.js:29:6038)'
}

Environment (please complete the following information):

  • ZenStack version: 2.10.2, 2.11.3
  • Prisma version: 6.1.0
  • Database type: SQLite, PostgreSQL

Additional context

  • Issue seem to be linked with the usage of composite key in the update({ where call. If where is using PK then above code works fine.
  • The same as in the example for update+deleteMany happens with update+upsert.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions