question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Postgres: Deleting a record that doesn't exist gives a bad error

See original GitHub issue

Problem

The error we get back from bigserial ids it not very nice.

await prisma.types.delete({
  where: {
    bigserial: "non-existent id",
  },
})
PrismaClientKnownRequestError2: 
Invalid `prisma.types.delete()` invocation in
/Users/m/Go/src/github.com/prisma/qa-native-types/index.ts:72:30

   68 //   },
   69 // })
   70 
   71 console.log(
→  72   await prisma.types.delete(
  Query interpretation error. Error for binding '0': RecordNotFound("Record to delete does not exist.")
    at PrismaClientFetcher.request (/Users/m/Go/src/github.com/prisma/qa-native-types/node_modules/@prisma/client/runtime/index.js:15871:15)
    at processTicksAndRejections (internal/process/task_queues.js:97:5) {
  code: 'P2016',
  clientVersion: '2.10.0-dev.58',
  meta: {
    details: `Error for binding '0': RecordNotFound("Record to delete does not exist.")`
  }
}

Suggested Solution

Remove Query interpretation error. Error for binding '0':

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:22
  • Comments:14 (2 by maintainers)

github_iconTop GitHub Comments

22reactions
jake-chamberscommented, Jan 29, 2022

I have this issue as well, deleteIfExists?

12reactions
CDDeltacommented, Mar 4, 2022

It would be great to have something akin to the following for delete():

await this.prisma.product.delete({
    where: {
      id: product.id,
    },
    rejectOnNotFound: false,
});

The current behavior makes things hard to deal with when trying to write idempotent functions for handling Stripe webhooks etc.

While using deleteMany() is a decent workaround it doesn’t work in cases such as the below:

await this.prisma.product.update({
  where: {
    id: product.id,
  },
  data: {
    price: {
        delete: true,
    }
  },
});

Something akin to the following would be handy as well:

await this.prisma.product.update({
  where: {
    id: product.id,
  },
  data: {
    price: {
        delete: {
           rejectOnNotFound: false,
        },
    }
  },
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

Deleting with NOT EXISTS vs NOT IN gives different results
When I check the records deleted by #1 they really do not exist in either house or office . postgresql · Share.
Read more >
delete "column does not exist" - Stack Overflow
I'm trying to execute a very simple delete query in Postgres. Query: delete ...
Read more >
Documentation: 15: DELETE - PostgreSQL
DELETE deletes rows that satisfy the WHERE clause from the specified table. If the WHERE clause is absent, the effect is to delete...
Read more >
Troubleshooting migration tasks in AWS Database Migration ...
To restart your task and avoid these errors, remove rows inserted into the ... In FULL LOB or LIMITED LOB mode, AWS DMS...
Read more >
PostgreSQL column does not exist | Definition and Syntax
PostgreSQL column does not exist exception occurs when we have used column did not exist in the table or it will occur when...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found