Every condition on a deleteMany call is satisfied if none of the records meet the criteria #18193
Labels
bug/1-unconfirmed
Bug should have enough information for reproduction, but confirmation has not happened yet.
kind/bug
A reported bug.
team/client
Issue for team Client.
topic: deleteMany()
Bug description
Recently ran into a bit of a nasty bug related to the every filter for a deleteMany call. I had a prisma deleteMany call set up like so:
and a Dog record in my database structured like so:
I would expect that deleteMany call to be a no-op because there are no dogs with the breed “BEAGLE” where all of the owners have name “Sam Sokolin”. However, what ended up happening is that owners resulted in an empty array and the every condition was satisfied. Thus the deleteMany call attempted to delete the “John Smith”-owned dog record which failed due to a foreign key constraint. The deleteMany call was part of a transaction which was used to make updates to the Owner table and consequently every single update to the Owner table was failing, even though none of them were updating “John Smith”.
The remediation to this bug was updating the deleteMany call to be one of these two options:
To me, it feels odd that the every condition passes if NONE of the owners have the correct name. I’m not sure if this is by design, or indeed a Prisma bug, but figured it was at least worth flagging for discussion! Curious to hear thoughts!
How to reproduce
N/a
Expected behavior
The initial deleteMany call to be a no-op.
Prisma information
Redacted schema and actual code in favor of a parallel example with 🐶s. Let me know if it's unclear or needs further explanation!
Prisma version info:
Environment & setup
Prisma Version
The text was updated successfully, but these errors were encountered: