[go: nahoru, domu]

Skip to content
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

Prisma Client: Unknown Argument #24622

Closed
cadinhoruf opened this issue Jun 24, 2024 · 5 comments
Closed

Prisma Client: Unknown Argument #24622

cadinhoruf opened this issue Jun 24, 2024 · 5 comments
Assignees
Labels
bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. domain/client Issue in the "Client" domain: Prisma Client, Prisma Studio etc. kind/bug A reported bug.

Comments

@cadinhoruf
Copy link
cadinhoruf commented Jun 24, 2024

Bug description

When attempting to create a record in the logTables model using Prisma Client, I encounter the following error: "Unknown argument usuarioId. Available options are marked with ?". The usuarioId field is defined in the Prisma schema, and querying the database with this field works.

How to reproduce

I Call the api route and this error returns for me.

Expected behavior

Based in the schemas, i need to not return the error, because the fields exist in both tables.

Prisma information

model QSMS06 {
  id               Int       @id @default(autoincrement())
  usuarioId        Int
  dtVerificacao    DateTime  @db.DateTime
  filialId         Int
  projetoId        Int
  nmEnvolvido      String    @db.NVarChar(150)
  departamentoId   Int
  qsmsCatRiscoId   Int
  desvio           String    @db.NVarChar(150)
  acaoTomada       String    @db.NVarChar(255)
  resolvido        Boolean
  justificativa    String    @db.NVarChar(255)
  dtPrazoAdequacao DateTime  @db.DateTime
  foto             Bytes?
  dtCriacao        DateTime? @default(now()) @db.DateTime
  dtAtualizacao    DateTime? @db.DateTime
  stAcao           String?
  dtAdequacao      DateTime? @db.DateTime
  observacao       String?
  FUNC01           FUNC01    @relation(fields: [departamentoId], references: [id], onUpdate: NoAction)
  EMPR01           EMPR01    @relation(fields: [filialId], references: [id], onUpdate: NoAction)
  EMPR03           EMPR03    @relation(fields: [projetoId], references: [id], onUpdate: NoAction)
  QSMS04           QSMS04    @relation(fields: [qsmsCatRiscoId], references: [id], onUpdate: NoAction)
  USER00           USER00    @relation(fields: [usuarioId], references: [id])
  QSMS06L          QSMS06L[]
}


model QSMS06L {
  id               Int       @id @default(autoincrement())
  aQsmsDesviosId   Int?
  usuarioId        Int?
  dtVerificacao    DateTime? @db.DateTime
  filialId         Int?
  projetoId        Int?
  nmEnvolvido      String?   @db.NVarChar(150)
  departamentoId   Int?
  qsmsCatRiscoId   Int?
  desvio           String?   @db.NVarChar(150)
  acaoTomada       String?   @db.NVarChar(255)
  resolvido        Boolean?
  justificativa    String?   @db.NVarChar(255)
  dtPrazoAdequacao DateTime?
  dtCriacao        DateTime? @db.DateTime
  dtAtualizacao    DateTime? @default(now()) @db.DateTime
  stAcao           String?
  acao             String?
  dtAdequacao      DateTime?
  observacao       String?
  QSMS06           QSMS06?   @relation(fields: [aQsmsDesviosId], references: [id], onDelete: NoAction, onUpdate: NoAction)
  FUNC01           FUNC01?   @relation(fields: [departamentoId], references: [id], onDelete: NoAction, onUpdate: NoAction)
  EMPR01           EMPR01?   @relation(fields: [filialId], references: [id], onDelete: NoAction, onUpdate: NoAction)
  EMPR03           EMPR03?   @relation(fields: [projetoId], references: [id], onDelete: NoAction, onUpdate: NoAction)
  QSMS04           QSMS04?   @relation(fields: [qsmsCatRiscoId], references: [id], onDelete: NoAction, onUpdate: NoAction)
  USER00           USER00?   @relation(fields: [usuarioId], references: [id], onDelete: NoAction, onUpdate: NoAction)
}

TS

const updateDetour = async (id: number, payload: DetourUpdate): Promise<Detour> => {
  if (payload.dtAdequacao) {
    const isoDate = new Date(payload.dtAdequacao).toISOString();
    const pictureBuffer = Buffer.from(payload.foto!);

    const detour = await prisma.qSMS06.update({
      where: { id },
      data: {
        dtAdequacao: isoDate,
        observacao: payload.observacao,
        usuarioId: payload.usuarioId,
        dtAtualizacao: new Date()
      },
    });

    await prisma.qSMS06L.create({
      data: {
        ...payload,
        aQsmsDesviosId: id,
        acao: 'U',
        dtAdequacao: isoDate,
      },
    });

    const items = [
      { foto: pictureBuffer, aDesviosId: id, adequacao: true, usuarioId: 1 },
    ];

    for (const item of items) {
      const adequated = await prisma.qSMS07.create({ data: item });
      await prisma.qSMS07L.create({
        data: {
          aDesviosFotoId: adequated.id,
          acao: 'C',
          dtCriacao: new Date(),
          usuarioId: payload.usuarioId ? payload.usuarioId : 0,
        },
      });
    }
    return detourSchema.parse({ ...detour, foto: payload.foto ? [payload.foto[0].toString('base64')] : [] });
  } else {


    const detour = await prisma.qSMS06.update({
      where: { id },
      data: {
        ...payload,
        foto: payload.foto ? payload.foto[0] : null,
        stAcao: 'A',
        dtAtualizacao: new Date()
      },
    });

    await prisma.qSMS06L.create({
      data: {
        ...payload,
        aQsmsDesviosId: id,
        acao: 'U',
        stAcao: 'A',
        dtCriacao: detour.dtCriacao,
      },
    });
    return detourSchema.parse({ ...detour, foto: payload.foto ? [payload.foto[0].toString('base64')] : [] });
  }
};

Environment & setup

  • OS: Windows 11
  • Database: SQLServer
  • Node.js version: v20.13.1

Prisma Version

prisma : 5.15.1
@prisma/client : 5.15.1

Error

await app_1.prisma.qSMS06L.create({
       data: {
         usuarioId: 4,
         ~~~~~~~~~
         observacao: "adequado",
         dtAdequacao: "2024-06-24T00:00:00.000Z",
         aQsmsDesviosId: 22,
         acao: "U",
     ?   dtVerificacao?: DateTime | Null,
     ?   nmEnvolvido?: String | Null,
     ?   desvio?: String | Null,
     ?   acaoTomada?: String | Null,
     ?   resolvido?: Boolean | Null,
     ?   justificativa?: String | Null,
     ?   dtPrazoAdequacao?: DateTime | Null,
     ?   dtCriacao?: DateTime | Null,
     ?   dtAtualizacao?: DateTime | Null,
     ?   stAcao?: String | Null,
     ?   QSMS06?: QSMS06CreateNestedOneWithoutQSMS06LInput,
     ?   FUNC01?: FUNC01CreateNestedOneWithoutQSMS06LInput,
     ?   EMPR01?: EMPR01CreateNestedOneWithoutQSMS06LInput,
     ?   EMPR03?: EMPR03CreateNestedOneWithoutQSMS06LInput,
     ?   QSMS04?: QSMS04CreateNestedOneWithoutQSMS06LInput,
     ?   USER00?: USER00CreateNestedOneWithoutQSMS06LInput
       }
     })

Unknown argument `usuarioId`. Available options are marked with ?.
@cadinhoruf cadinhoruf added the kind/bug A reported bug. label Jun 24, 2024
@laplab laplab added bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. domain/client Issue in the "Client" domain: Prisma Client, Prisma Studio etc. labels Jun 25, 2024
@jkomyno
Copy link
Contributor
jkomyno commented Jun 27, 2024

Hello @cadinhoruf, I couldn't reproduce this issue.
Here are the Prisma Schema and Client snippets I was able to use (please note that many relations that were referenced in your Prisma Schema refer to models which were not posted):

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

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

model QSMS06 {
  id               Int       @id @default(autoincrement())
  usuarioId        Int
  dtVerificacao    DateTime  @db.DateTime
  filialId         Int
  projetoId        Int
  nmEnvolvido      String    @db.NVarChar(150)
  departamentoId   Int
  qsmsCatRiscoId   Int
  desvio           String    @db.NVarChar(150)
  acaoTomada       String    @db.NVarChar(255)
  resolvido        Boolean
  justificativa    String    @db.NVarChar(255)
  dtPrazoAdequacao DateTime  @db.DateTime
  foto             Bytes?
  dtCriacao        DateTime? @default(now()) @db.DateTime
  dtAtualizacao    DateTime? @db.DateTime
  stAcao           String?
  dtAdequacao      DateTime? @db.DateTime
  observacao       String?
  QSMS06L          QSMS06L[]
}

model QSMS06L {
  id               Int       @id @default(autoincrement())
  aQsmsDesviosId   Int?
  usuarioId        Int?
  dtVerificacao    DateTime? @db.DateTime
  filialId         Int?
  projetoId        Int?
  nmEnvolvido      String?   @db.NVarChar(150)
  departamentoId   Int?
  qsmsCatRiscoId   Int?
  desvio           String?   @db.NVarChar(150)
  acaoTomada       String?   @db.NVarChar(255)
  resolvido        Boolean?
  justificativa    String?   @db.NVarChar(255)
  dtPrazoAdequacao DateTime?
  dtCriacao        DateTime? @db.DateTime
  dtAtualizacao    DateTime? @default(now()) @db.DateTime
  stAcao           String?
  acao             String?
  dtAdequacao      DateTime?
  observacao       String?
  QSMS06           QSMS06?   @relation(fields: [qSMS06Id], references: [id])
  qSMS06Id         Int?
}
import { PrismaClient } from '@prisma/client'

const prisma = new PrismaClient()

async function main() {
  const isoDate = new Date().toISOString();

  await prisma.qSMS06L.create({
    data: {
      usuarioId: 4,
      observacao: 'adequado',
      aQsmsDesviosId: 22,
      acao: 'U',
      dtAdequacao: isoDate,
    },
  });
}

main()

Can you please double-check that you re-ran prisma db push or prisma generate after modifying the schema? Thanks.

@cadinhoruf
Copy link
Author
cadinhoruf commented Jun 27, 2024

Hey jkomyno, this problem happens sometimes, when I open this problem, it was happening, but now it is no longer.

The problem is basically when there is a foreign key, sometimes in the log tables it does not recognize the id, even though it exists, and the relationship between the tables also exists.

This is the table of users :

model USER00 {
  id             Int       @id @unique @default(autoincrement())
  nome           String    @db.NVarChar(100)
  email          String    @unique @db.NVarChar(60)
  st             Boolean
  dtCriacao      DateTime? @default(now(), map: "DF__tmp_ms_xx__dtCri__2097C3F2") @db.DateTime
  dtAtualizacao  DateTime? @db.DateTime
  aprovador      Boolean?
  senha          String?   @db.NVarChar(100)
  admin          Boolean?
  departamentoId Int?
  usuarioId      Int?
  CKLT00         CKLT00[]
  CKLT00L        CKLT00L[]
  CKLT01         CKLT01[]
  CKLT01L        CKLT01L[]
  CKLT02         CKLT02[]
  CKLT02L        CKLT02L[]
  CKLT03         CKLT03[]
  CKLT03L        CKLT03L[]
  CKLT04         CKLT04[]
  CKLT04L        CKLT04L[]
  CKLT05         CKLT05[]
  CKLT05L        CKLT05L[]
  CKLT06         CKLT06[]
  CKLT06L        CKLT06L[]
  CKLT07         CKLT07[]
  CKLT07L        CKLT07L[]
  CKLT08         CKLT08[]
  CKLT08L        CKLT08L[]
  CKLT09         CKLT09[]
  CKLT09L        CKLT09L[]
  CKLT10         CKLT10[]
  CKLT10L        CKLT10L[]
  CKLT11         CKLT11[]
  CKLT11L        CKLT11L[]
  DCMT00         DCMT00[]
  DCMT00L        DCMT00L[]
  DCMT01         DCMT01[]
  DCMT01L        DCMT01L[]
  DCMT02         DCMT02[]
  DCMT02L        DCMT02L[]
  DCMT03         DCMT03[]
  DCMT03L        DCMT03L[]
  DCMT04         DCMT04[]
  DCMT04L        DCMT04L[]
  DCMT05         DCMT05[]
  DCMT05L        DCMT05L[]
  DCMT06         DCMT06[]
  DCMT06L        DCMT06L[]
  EMPR00         EMPR00[]
  EMPR00L        EMPR00L[]
  EMPR01         EMPR01[]
  EMPR01L        EMPR01L[]
  EMPR02         EMPR02[]
  EMPR02L        EMPR02L[]
  EMPR03         EMPR03[]
  EMPR03L        EMPR03L[]
  EQPM00         EQPM00[]
  EQPM00L        EQPM00L[]
  EQPM01         EQPM01[]
  EQPM01L        EQPM01L[]
  EQPM02         EQPM02[]
  EQPM02L        EQPM02L[]
  EQPM03         EQPM03[]
  EQPM03L        EQPM03L[]
  EQPM04         EQPM04[]
  EQPM04L        EQPM04L[]
  EQPM05         EQPM05[]
  EQPM05L        EQPM05L[]
  EQPM06         EQPM06[]
  EQPM06L        EQPM06L[]
  EQPM07         EQPM07[]
  EQPM07L        EQPM07L[]
  EQPM08         EQPM08[]
  EQPM08L        EQPM08L[]
  EQPM09         EQPM09[]
  EQPM09L        EQPM09L[]
  EQPM10         EQPM10[]
  EQPM10L        EQPM10L[]
  FUNC00         FUNC00[]
  FUNC00L        FUNC00L[]
  FUNC01L        FUNC01L[]
  FUNC02         FUNC02[]
  FUNC02L        FUNC02L[]
  FUNC03         FUNC03[]
  FUNC03L        FUNC03L[]
  GEOG00         GEOG00[]
  GEOG00L        GEOG00L[]
  GEOG01         GEOG01[]
  GEOG01L        GEOG01L[]
  GEOG02         GEOG02[]
  GEOG02L        GEOG02L[]
  GEOG03         GEOG03[]
  GEOG03L        GEOG03L[]
  GEOG04         GEOG04[]
  GEOG04L        GEOG04L[]
  GEOG05         GEOG05[]
  GEOG05L        GEOG05L[]
  operador       HELP00[]  @relation("Operador")
  solicitante    HELP00[]  @relation("Solicitante")
  HELP00L        HELP00L[]
  HELP01         HELP01[]
  HELP01L        HELP01L[]
  HELP02         HELP02[]
  HELP02L        HELP02L[]
  HELP03         HELP03[]
  HELP03L        HELP03L[]
  HELP04         HELP04[]
  HELP04L        HELP04L[]
  HELP05         HELP05[]
  HELP05L        HELP05L[]
  HELP06         HELP06[]
  HELP06L        HELP06L[]
  HELP07         HELP07[]
  HELP07L        HELP07L[]
  ITEM01         ITEM01[]
  ITEM01L        ITEM01L[]
  QSMS00         QSMS00[]
  QSMS01         QSMS01[]
  QSMS01L        QSMS01L[]
  QSMS02         QSMS02[]
  QSMS02L        QSMS02L[]
  QSMS03         QSMS03[]
  QSMS03L        QSMS03L[]
  QSMS04         QSMS04[]
  QSMS04L        QSMS04L[]
  QSMS06         QSMS06[]
  QSMS06L        QSMS06L[]
  QSMS07         QSMS07[]
  QSMS07L        QSMS07L[]
  QSMS08         QSMS08[]
  QSMS08L        QSMS08L[]
  QSMS09L        QSMS09L[]
  QSMS10         QSMS10[]
  QSMS10L        QSMS10L[]
  QSMS13         QSMS13[]
  QSMS13L        QSMS13L[]
  QSMS14         QSMS14[]
  QSMS14L        QSMS14L[]
  FUNC01         FUNC01?   @relation(fields: [departamentoId], references: [id])
  USER00L        USER00L[]
  USER01         USER01[]
  USER01L        USER01L[]
  USER02         USER02[]
  USER02L        USER02L[]
  USER03         USER03[]
  USER03L        USER03L[]
  QSMS15         QSMS15[]
  QSMS15L        QSMS15L[]
  QSMS16         QSMS16[]
  QSMS16L        QSMS16L[]
  QSMS17         QSMS17[]
  QSMS17L        QSMS17L[]

  @@index([email])
}

Thx for the support

@jkomyno
Copy link
Contributor
jkomyno commented Jul 1, 2024

Hey @cadinhoruf, can you please provide a self-contained reproduction of this problem? Providing just a few models at a time unfortunately doesn't help, as we see you have tens of relations, each of which may have a foreign key constraint.

If you manage to provide a small repro, that'd be great, as it'd allow us to pinpoint the issue quickly and hopefully provide a fix in a timely manner. Thanks!

@cadinhoruf
Copy link
Author

The problem didn't happen again.

@doylio
Copy link
doylio commented Jul 10, 2024

I am still experiencing this bug.

UPDATE: I figured out what the problem was. The error message was incorrect. My schema looks something like this:

model Organization {
  additionalChargesIncomeAccountId: BigInt? 
  additionalChargesIncomAccount: Account? @relation("additionalChargesIncomeAccount", fields: [additionalChargesIncomeAccountId], references: [id])
  // and a bunch of other stuff
}

When I passed in an object to the prisma.organization.create({ data: newOrganization }) it would throw the following error:

 Unknown argument `additionalChargesIncomeAccountId`. Did you mean `additionalChargesIncomeAccount`? Available options are marked with ?.

Even though additionalChargesIncomeAccountId is a valid input, that was not the problem. The problem was there was an additional property on the newOrganization object that was not a valid column, but the error message seems to have been confused

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. domain/client Issue in the "Client" domain: Prisma Client, Prisma Studio etc. kind/bug A reported bug.
Projects
None yet
Development

No branches or pull requests

4 participants