ORM: where({}) counts as a filter, so where({}).deleteAll() deletes every row
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 35/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- mongodb, postgresql, sqlite, typescript
- Domain
- databases
Research direction
Read ADR 265 and the related issue #30784/PR #30785 first. The issue points to collection.state.test.ts and identifies separate SQL and MongoDB behavior; trace their where and bulk write checks. Done means a design decision defines explicit opt-in and consistent compile-time and runtime checks for both ORM families, with clear error messages.
Written by the indexing model from the issue text.
Description
Problem
The ORM refuses a bulk write with no filter at compile time:
await db.orm.public.User.deleteAll();
// error: The 'this' context of type 'Collection<...>' is not assignable to method's 'this' of type 'HasWhere'
An empty filter gets past that check:
await db.orm.public.User.where({}).deleteAll(); // compiles; on Postgres and SQLite it runs DELETE FROM "user"
A call that deletes every row should be something the user clearly opts into. where({}) does not read as "delete everything", and it is easy to produce by accident, for example from a filter object built up from optional inputs that all turned out empty.
What happens today
- The compile-time check.
update,updateAll,updateAndCount,delete,deleteAllanddeleteAndCountrequire a collection known to be filtered (A collection keeps its class through the chain). The same decision sayswhere(...)always marks the collection as filtered, and nothing excludes an empty object. Sowhere({})satisfies the check, in both the SQL and the MongoDB ORM. - SQL ORM at run time.
where({})returns the same collection (collection.state.test.ts:expect(collection.where({})).toBe(collection)), sodeleteAll()sends aDELETEwith noWHERE. The SQL ORM has no run-time equivalent of the compile-time check:deleteAll()checks for limits, offsets and locks, but not for a filter. - MongoDB ORM at run time.
where({})adds no filter, and a separate check throwsORM.WHERE_MISSING: "deleteAll() requires a .where() filter. Call .where() before .deleteAll()". The user did call.where(), which is the confusion in #30784. No design doc records why MongoDB has this check and SQL does not.
So the two ORMs behave differently, and on SQL nothing catches this at run time.
What we want
- Deleting or updating every row needs an explicit opt-in that reads as exactly that.
- A filter with no conditions, such as
where({}), does not count as a filter. - Both families check the same way, twice: the compile-time "is filtered" check, then a run-time check that refuses the same calls when the collection has no filter. The run-time check replaces MongoDB's own
ORM.WHERE_MISSINGcheck rather than sitting beside it. - The errors say how to opt in.
The shape of the opt-in is open. One possibility is a value the user imports and passes, such as where(ALL); that is an illustration, not a decision.
This changes what the decision above says where does, so it needs a design decision before implementation.
Related
- #30784, and its PR #30785, which improves MongoDB's message without changing the behaviour.
- Dominant language
- TypeScript
- Stars
- 47.8k
- Forks
- 2.6k
- Avg merge
- 1d 21h
- Merged PRs (30d)
- 227
Getting set up
- Ships a Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from prisma/orm
-
bug/1-unconfirmed kind/bug
Difficulty 1/5 Under an hour Newbie friendliness 90/100
Maintainers usually reply within 1 day
-
get-platform: distros with ID_LIKE=alpine are not detected as musl, so glibc engines are used on Alpine-based imagesPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
prisma/orm#31281 · 1 comment ·
Maintainers usually reply within 1 day
-
adapter-pg: connectToShadowDb connects to the main database when built from a connection stringMay be free again @cestercian claimed this 10 days ago, and no pull request is open. Open
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
prisma/orm#31196 · 1 comment ·
Maintainers usually reply within 1 day
-
[Prisma 8] Type-check time grows exponentially with chained .include() callsPossibly taken @SiKreuz claimed this 13 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
prisma/orm#31161 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
prisma/orm#31125 · 4 comments · 6 reactions ·
Maintainers usually reply within 1 day
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
tenstorrent/ttnn-visualizer#2526 ·
Maintainers usually reply within 1 day
-
trySessionCache calls /get-session twice when minting session_data (cache miss or expired cookie)Open
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
neondatabase/neon-js#301 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
tashfeenahmed/freellmapi#2305 ·
Maintainers usually reply within 1 day