Skip to content

Upsert inside update fails #764

@iksemot

Description

@iksemot

Description and expected behavior

Upsert operation on the relation fails if done inside an update method of a parent. The same is allowed with pure PrismaClient.

Environment

  • ZenStack version: 1.0.2
  • Prisma version: 5.4.2
  • Database type: sqlite, postgres

Additional context

Given data model:

// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

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

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

model User {
  id    Int     @id @default(autoincrement())
  name  String

  post   Post? @relation(fields: [postId], references: [id])
  postId Int?

  @@allow('all', true)
}

model Post {
  id    Int    @id @default(autoincrement())
  title String
  User  User[]

  @@allow('all', true)
}

Following code:

const prisma = enhance(new PrismaClient(), {})

const user = await prisma.user.create({
  data: { name: 'Me' }
})

await prisma.user.update({
  where: { id: user.id },
  data: {
    post: {
      upsert: {
        create: {
          title: 'Hello World'
        },
        update: {
          title: 'Hello World'
        }
      }
    }
  }
})

errors with:

Error calling enhanced Prisma method `update`: 
Invalid `prisma.user.findFirst()` invocation:

{
  where: {
    some: {
    ~~~~
      id: 1
    },
?   AND?: UserWhereInput | UserWhereInput[],
?   OR?: UserWhereInput[],
?   NOT?: UserWhereInput | UserWhereInput[],
?   id?: IntFilter | Int,
?   name?: StringFilter | String,
?   postId?: IntNullableFilter | Int | Null,
?   post?: PostNullableRelationFilter | PostWhereInput | Null
  },
  select: {
    id: true
  }
}

Unknown argument `some`. Did you mean `name`? Available options are marked with ?.
    at C:\Users\tomas\workspace\playground\zenstack_\src\zenstack.ts:12:23,
    at Generator.next (<anonymous>),
    at fulfilled (C:\Users\tomas\workspace\playground\zenstack_\src\zenstack.ts:5:58) {
  name: 'PrismaClientValidationError',
  clientVersion: '5.4.2',
  internalStack: 'PrismaClientValidationError: \n' +
    'Invalid `prisma.user.findFirst()` invocation:\n' +
    '\n' +
    '{\n' +
    '  where: {\n' +
    '    some: {\n' +
    '    ~~~~\n' +
    '      id: 1\n' +
    '    },\n' +
    '?   AND?: UserWhereInput | UserWhereInput[],\n' +
    '?   OR?: UserWhereInput[],\n' +
    '?   NOT?: UserWhereInput | UserWhereInput[],\n' +
    '?   id?: IntFilter | Int,\n' +
    '?   name?: StringFilter | String,\n' +
    '?   postId?: IntNullableFilter | Int | Null,\n' +
    '?   post?: PostNullableRelationFilter | PostWhereInput | Null\n' +
    '  },\n' +
    '  select: {\n' +
    '    id: true\n' +
    '  }\n' +
    '}\n' +
    '\n' +
    'Unknown argument `some`. Did you mean `name`? Available options are marked with ?.\n' +
    '    at En (C:\\Users\\tomas\\workspace\\playground\\zenstack_\\node_modules\\@prisma\\client\\runtime\\library.js:116:5888)\n' +
    '    at Cn.handleRequestError (C:\\Users\\tomas\\workspace\\playground\\zenstack_\\node_modules\\@prisma\\client\\runtime\\library.js:123:6516)\n' +
    '    at Cn.handleAndLogRequestError (C:\\Users\\tomas\\workspace\\playground\\zenstack_\\node_modules\\@prisma\\client\\runtime\\library.js:123:6206)\n' +
    '    at Cn.request (C:\\Users\\tomas\\workspace\\playground\\zenstack_\\node_modules\\@prisma\\client\\runtime\\library.js:123:5926)\n' +
    '    at async l (C:\\Users\\tomas\\workspace\\playground\\zenstack_\\node_modules\\@prisma\\client\\runtime\\library.js:128:9968)'
}

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