-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[REST] DELETE with invalid ID is successful #1472
Comments
Actually, if you call the DELETE operation with no WHERE clause, it will remove ALL records. I think the juggler Delete All is not checking the empty where clause either. For security this should be disable. What we do for now is that we override these delete methods and place our own validations. |
Is this perhaps related to PersistedModel.destroyAll has very dangerous behaviour if the filter is not passed in correctly strongloop/loopback#3094? |
It is not related, The DEL operation on endpoint /mymodel/{id} (deleteById) where ID doesn't exist returns an http 200 status with empty response body instead of 404 probably. If {id} exists it returns 200 status with true in the response body. |
However, on DeleteAll() I believe which is the main problem because users can delete all their records in one operation, we should read the record first, even if that means a double operation on DeleteAll. if (!where) { throw an exception } if (find) { //find with where clause included, we can place a count instead (less expensive) This way if the user sends an invalid where clause we don't issue the delete operation at all. If users really need to delete All records they should pass where 1=1 (which is always true) in the where clause. |
@marioestradarosa In that case, let's discuss |
Let's discuss this, I can see good reasons why it may be actually a good thing to return 200 even when the requested id does not exist. Here are two use cases I have in mind:
I am arguing that we should return 200 OK in both cases. The intention was fulfilled - the record-to-be-deleted no longer exists. Now if we return 404, then clients have to implemented additional error handling to distinguish between 404 (record no longer exists) and other kinds of errors. This is poor user/developer experience to me. Having wrote all of this, it looks like most of the internet is of a different opinion and thinks that DELETE request with an unknown ID should return 404 indeed.
In that light, I am fine to proceed and change our DELETE operation to return 404 when the id provided by the client does not exist. |
Great!. And yes, the delete operation on a database is idempotent even when the response code should be different (the first one would receive 200 and subsequent ones will receive 404 in a race condition). For simplicity the client application would receive 200 or 404 and act upon it accordingly to its needs. For example, the user could receive "Record successfully deleted" or "The record was not found" and that should be enough information for him/her. |
I agree that sending 200 OK for non-existing records isn't particularly wrong because that is the correct state on the server ... I'm ok with either or but personally prefer returning a |
fix _DELETE with invalid ID is successful #1472_
fix _DELETE with invalid ID is successful #1472_
document the behavior of delete operations on non-existent resources.
document the behavior of delete operations on non-existent resources.
document the behavior of delete operations on non-existent resources.
document the behavior of delete operations on non-existent resources.
Cross-posting our discussion from elsewhere: In LoopBack 3.x, we have a model-level setting I think at the time we were implementing I have already changed LB models to be |
Fixed by #1621. |
Description / Steps to reproduce / Feature proposal
From #1206
examples/todo
, using the API Explorer make a request to theDELETE
endpoint. Useid
2 / something that doesn't exist.id
doesn't exist.Current Behavior
Expected Behavior
See Reporting Issues for more tips on writing good issues
The text was updated successfully, but these errors were encountered: