loopbackio / loopbackio/loopback-next
Patch with no query updates all records in the database
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- TypeScript
- Estrellas
- 5.1k
- Forks
- 1.1k
- Merge medio
- 2 d 21 h
- PR fusionados (30 d)
- 27
Descripción
While struggling to to learn how to write the correct query
to patch only one record, I tried no query and the default of
patch all records was performed.
Steps to reproduce
- Following the the todo-list tutorial
lb4 example todo-list
cd loopback4-example-todo-list
npm start
-
Browse to the API explorer at http://127.0.0.1:3000
-
Notice that the database is prepopulated
a. With GET todo-lists/count
- Click
Try It out - remove the default query
- press the
executebutton - 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
1for 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) patch all the todos in the list!
d. Click button
PATCH /todo-lists/{id}/todos- Click
Try It out - Enter
1for the id number of the first list - remove the default query
- add some replacement data in the request body, for example:
{ "id": 4, "title": "my-title-string", "desc": "a short description string", "isComplete": false, "todoListId": 1 } - press the
executebutton - see the response is
{ "count": 3 }
e. Re-perform step c. above to see the result is:
[ { "id": 1, "title": "my-title-string", "desc": "a short description string", "isComplete": false, "todoListId": 1 }, { "id": 2, "title": "my-title-string", "desc": "a short description string", "isComplete": false, "todoListId": 1 }, { "id": 4, "title": "my-title-string", "desc": "a short description string", "isComplete": false, "todoListId": 1 } ]- an array where all the records have been unceremoniously patched to equal the replacement data! The list count is still { "count": 2 }.
- Click
Current Behavior
- Default (accidental) patch of all records.
Expected Behavior
- My expectation is that at least nothing would happen
accidentally. Even better, no patch-all would occur
and that a somewhat helpful error message would be
returned stating that an empty query is not allowed with
a patch request.
Link to reproduction sandbox
__N/A__
Additional information
- linux x64 14.15.1
@loopback/example-todo-list@3.7.1 /home/northdecoder/workspace/loopback4-example-todo-list
├── @loopback/boot@3.2.0
├── @loopback/core@2.14.0
├── @loopback/repository@3.4.0
├── @loopback/rest@9.1.2
├── @loopback/rest-explorer@3.0.6
├── @loopback/service-proxy@3.0.6
├── loopback-connector-rest@4.0.1
Related Issues
Issue #
- Deletes all with no query issue# 7017. Not sure the code is related, however the pattern of behavior is similar.
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Empieza reproduciendo el PATCH con una consulta vacía a través del endpoint del API Explorer del tutorial de todo-list y, después, inspecciona los paquetes @loopback/repository y @loopback/rest implicados en su gestión. Compara el comportamiento con el issue relacionado #7017. Se considera terminado cuando una consulta vacía ya no aplica un patch a todos los todo y el endpoint devuelve un error útil o, de lo contrario, no realiza ninguna actualización.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- nodejs, typescript
- Área
- api, backend
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 25/100