loopbackio / loopbackio/loopback-next

Delete with no query removes all records by default

Open
#7,017 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
TypeScript
Stars
5.1k
Forks
1.1k
Avg merge
2d 21h
Merged PRs (30d)
27

Description

While struggling to to learn how to write the correct query
to delete only one record, I tried no query and the default of
delete all records was performed.

Steps to reproduce

  1. Following the the todo-list tutorial
lb4 example todo-list
cd loopback4-example-todo-list
npm start
  1. Browse to the API explorer at http://127.0.0.1:3000

  2. Notice that the database is prepopulated

    a. With GET todo-lists/count

    • Click Try It out
    • remove the default query
    • press the execute button
    • see result { "count": 2 }

    b. With button GET todo-lists/

    • Click Try It out
    • remove the default query
    • press the execute button
    • see the response has two lists
      	[
      	  {
      	    "id": 1,
      	    "title": "Sith lord's check list",
      	    "color": "blue"
      	  },
      	  {
      	    "id": 2,
      	    "title": "My daily chores",
      	    "color": "red"
      	  }
      	]
      

    c. Click button GET /todo-lists/{id}/todos

    • Click Try It out
    • Enter 1 for the id number of the first list
    • remove the default query
    • press the execute button
    • see the response is quantity three pre-populated todos
      id's 1, 2 and 4 .

    WARNING: about to (accidentally) delete all the todos in the list!

    d. Click button DELETE /todo-lists/{id}/todos

    • Click Try It out
    • Enter 1 for the id number of the first list
    • remove the default query
    • press the execute button
    • see the response is
      {
        "count": 3
      }
      

    e. Re-perform step c. above to see the result is [], an
    empty array. All records have been unceremoniously deleted
    from list 1! The list count is still { "count": 2 }.

Current Behavior

  • Default (accidental) delete of all records.

Expected Behavior

  • My expectation is that at least nothing would happen
    accidentally. Even better, no delete-all would occur
    and that a somewhat helpfull error message would be
    returned stating that an empty query is not allowed with
    a delete request.

Link to reproduction sandbox

N/A

Additional information

  • linux x64 14.15.1

@loopback/example-todo-list@3.7.0 /home/northdecoder/workspace/loopback4-example-todo-list
├── @loopback/boot@3.1.2
├── @loopback/core@2.13.1
├── @loopback/repository@3.3.0
├── @loopback/rest@9.1.1
├── @loopback/rest-explorer@3.0.5
├── @loopback/service-proxy@3.0.5
├── loopback-connector-rest@4.0.1

Related Issues

Thinking this may have already been discussed, I read through
a bunch of issues with 'delete' somewhere in the text. Not sure
of the relevance.

Issue #

See Reporting Issues for more tips on writing good issues

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at DELETE /todo-lists/{id}/todos in the generated todo-list example and trace the repository delete operation used when the query is empty. Reproduce the behavior in API Explorer, then verify that an empty delete query is rejected without removing records and that the existing list and count behavior remains intact.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, typescript
Domain
api, database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.