Skip to content

PrismaClientValidationError - Missing messageId in MessageUpdate creation #2080

@Davi-AMF

Description

@Davi-AMF

Welcome!

  • Yes, I have searched for similar issues on GitHub and found none.

What did you do?

When DATABASE_SAVE_MESSAGE_UPDATE=true is enabled, the application frequently fails to create MessageUpdate records due to a missing required messageId field, resulting in PrismaClientValidationError exceptions.
The application attempts to create MessageUpdate records without providing the required messageId field, causing Prisma validation to fail. According to the database schema, messageId is a required (NOT NULL) field with a foreign key constraint to the Message table.

Table "MessageUpdate"
  messageId   text   NOT NULL

Foreign-key constraint:
  "MessageUpdate_messageId_fkey" FOREIGN KEY ("messageId")
    REFERENCES "Message"(id) ON DELETE CASCADE

Location: src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts

  • Line 1508: Status update creation (first occurrence)
  • Line 1554: Status update creation (second occurrence)

Problem: The messageId field is added conditionally, causing failures when:

  • Database configuration does NOT have HISTORIC or NEW_MESSAGE enabled
  • Or when the parent message is not found in the database
// Lines 1479-1508 and 1551-1554
const message: any = {
  keyId: key.id,
  remoteJid: key?.remoteJid,
  fromMe: key.fromMe,
  participant: key?.remoteJid,
  status: status[update.status] ?? 'DELETED',
  pollUpdates,
  instanceId: this.instanceId,
  // ⚠️ messageId is NOT here initially
};

messageId is only added IF these conditions are true:

  if (configDatabaseData.HISTORIC || configDatabaseData.NEW_MESSAGE) {
    const messages = await this.prismaRepository.$queryRaw`
      SELECT id FROM "Message"
      WHERE "instanceId" = ${this.instanceId}
      AND "key"->>'id' = ${key.id}
      LIMIT 1
    `;
    findMessage = messages[0] || null;

    if (findMessage) message.messageId = findMessage.id; // ⚠️ Conditional!
  }

Both calls can fail if messageId is missing:

  await this.prismaRepository.messageUpdate.create({ data: message }); // Line 1508 ❌
  await this.prismaRepository.messageUpdate.create({ data: message }); // Line 1554 ❌

What did you expect?

The application should always provide a valid messageId when creating MessageUpdate records, or handle the case gracefully when the parent message doesn't exist.

What did you observe instead of what you expected?

The application throws PrismaClientValidationError: Argument 'Message' is missing when attempting to create MessageUpdate records. This occurs because the required messageId field is either conditionally added (only when specific config flags are enabled AND the parent message is found) or completely omitted (in the case of edited messages).

Screenshots/Videos

No response

Which version of the API are you using?

v2.3.4

What is your environment?

Docker

Other environment specifications

  • Prisma Client: 6.16.1
  • All 56 migrations are applied successfully. Database schema is up to date.
  • Configuration Tested
  DATABASE_PROVIDER=postgresql
  DATABASE_SAVE_DATA_NEW_MESSAGE=true
  DATABASE_SAVE_DATA_HISTORIC=true
  DATABASE_SAVE_MESSAGE_UPDATE=true

If applicable, paste the log output

 [Evolution API]    v2.3.4  261   -  Fri Oct 10 2025 14:02:07     ERROR   [unhandledRejection]  [object]
  PrismaClientValidationError:
  Invalid `this.prismaRepository.messageUpdate.create()` invocation in
  /evolution/dist/main.js:247:1169

    244   WHERE "instanceId" = ${this.instanceId}
    245   AND "key"->>'id' = ${i.id}
    246   LIMIT 1
  → 247 `)[0]||null,u&&(l.messageId=u.id)),n.message===null&&n.status===void
  0){this.sendDataWebhook("messages.delete",i),this.configService.get("DATABASE").SAVE_DATA.MESSAGE_UPDATE&&await
  this.prismaRepository.messageUpdate.create({
          data: {
            keyId: "3EB097CE6C9EB0568E0EC7",
            remoteJid: "5518997981710:16@s.whatsapp.net",
            fromMe: true,
            participant: "5518997981710:16@s.whatsapp.net",
            status: "DELIVERY_ACK",
            pollUpdates: undefined,
            instanceId: "12e9aef0-68d4-45de-af2f-1c9728a8468d",
        +   Message: {
        +     create: MessageCreateWithoutMessageUpdateInput | MessageUncheckedCreateWithoutMessageUpdateInput,
        +     connectOrCreate: MessageCreateOrConnectWithoutMessageUpdateInput,
        +     connect: MessageWhereUniqueInput
        +   }
          }
        })

  Argument `Message` is missing.
      at Nn (/evolution/node_modules/@prisma/client/runtime/library.js:29:1363)
      at ei.handleRequestError (/evolution/node_modules/@prisma/client/runtime/library.js:121:6911)
      at ei.handleAndLogRequestError (/evolution/node_modules/@prisma/client/runtime/library.js:121:6593)
      at ei.request (/evolution/node_modules/@prisma/client/runtime/library.js:121:6300)
      at async a (/evolution/node_modules/@prisma/client/runtime/library.js:130:9551)
      at async messages.update (/evolution/dist/main.js:247:1127) {
    clientVersion: '6.16.1'
  }
[Evolution API]    v2.3.4  261   -  Fri Oct 10 2025 14:02:10     ERROR   [unhandledRejection]  [object]
  PrismaClientValidationError:
  Invalid `this.prismaRepository.messageUpdate.create()` invocation in
  /evolution/dist/main.js:247:1169

    244   WHERE "instanceId" = ${this.instanceId}
    245   AND "key"->>'id' = ${i.id}
    246   LIMIT 1
  → 247 `)[0]||null,u&&(l.messageId=u.id)),n.message===null&&n.status===void
  0){this.sendDataWebhook("messages.delete",i),this.configService.get("DATABASE").SAVE_DATA.MESSAGE_UPDATE&&await
  this.prismaRepository.messageUpdate.create({
          data: {
            keyId: "A5DDF17E31AE63BE3FF3463F6D1D578F",
            remoteJid: "5518991335435@s.whatsapp.net",
            fromMe: false,
            participant: "5518991335435@s.whatsapp.net",
            status: "READ",
            pollUpdates: undefined,
            instanceId: "2c0806e5-c7b8-4069-bf05-c815864ecaa0",
        +   Message: {
        +     create: MessageCreateWithoutMessageUpdateInput | MessageUncheckedCreateWithoutMessageUpdateInput,
        +     connectOrCreate: MessageCreateOrConnectWithoutMessageUpdateInput,
        +     connect: MessageWhereUniqueInput
        +   }
          }
        })

  Argument `Message` is missing.
      at Nn (/evolution/node_modules/@prisma/client/runtime/library.js:29:1363)
      at ei.handleRequestError (/evolution/node_modules/@prisma/client/runtime/library.js:121:6911)
      at ei.handleAndLogRequestError (/evolution/node_modules/@prisma/client/runtime/library.js:121:6593)
      at ei.request (/evolution/node_modules/@prisma/client/runtime/library.js:121:6300)
      at async a (/evolution/node_modules/@prisma/client/runtime/library.js:130:9551)
      at async messages.update (/evolution/dist/main.js:247:1127) {
    clientVersion: '6.16.1'
  }

Additional Notes

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions