Skip to content

Bug - mutations with optimisticUpdate are failing since 2.9.1  #1878

@roomman

Description

@roomman

@ymc9 I've updated to 2.9.1 which includes your PR #1842, and I am seeing failing mutations, and no network requests being made, when optimisticUpdate: true.

The cases that are failing include optional "belongs-to" relationships where no relationship has yet been formed. For example:

model SomeModel {
  id                           String   @id @default(uuid())
  title                        String
  business               Business?          @relation(fields: [businessId], references: [id], onDelete: Cascade)
  businessId            String?

}

I am seeing this error:
Error - there was an error updating SomeModel TypeError: Cannot convert undefined or null to object

The error is about to the "business" relationship from the above schema, and an evaluation on this line from mutator.ts:

for (const [key, value] of Object.entries(resultData)) {

Because no business has been related to SomeModel the value of both business and businessId is null. Your change expects either an array or an object.

If I set optimisticUpdates: false for the mutation the error goes away and mutations are successful.

Should L165 be doing a null check?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions