-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Repo.delete exception not documented #2603
Repo.delete exception not documented #2603
Conversation
If a row is already deleted from db Repo.delete raises Ecto.StaleEntryError. This change docs this for the API.
❤️ 💚 💙 💛 💜 |
@josevalim I completely disagree with this solution. It is not the documentation that needs to be fixed, it is the If one wants to get an exception in case of a failure during deletion, e.g., because the item was not found, then one should call Note that the The same issue happens with |
Please see #2589. We are going to allow |
@josevalim I have a suggestion: why not set the action to |
There are two issues with this approach:
|
@josevalim Ok, I tested this
and adding an entry in But, why not put the error automatically on the primary key, like in this example? I am not seeing other |
Because:
|
Point 1, I did not understand. Point 2, if developers no longer handle the stale exception, I see them changing their code to look for errors of the primary key field. When the API changes, that is the expectable change as well. |
Sorry about 1, I meant to say doing this change would be backwards incompatible. While we are working on Ecto 3 now, we are still very conservative with changes, there is no reason to push changes to the user unless we have a very strong reason to, and I don't think we have one here. About point 2, that's exactly the point. The exception is really straight-forward to see and in the case you don't handle it, you likely get notified about it. If you forget to check the primary key, your users won't get any feedback and you won't ever know about it. |
@josevalim I think we are probably talking about different things. I don't mind adding an option to generate an error, instead of throwing an exception, for backwards compatibility. What I was asking is, in case the option to generate the error is passed, why not generate the error on the primary key field? |
Oh, I see, sorry! You can choose that if you want to. The argument to the option is exactly the field to add the error to. I can think of cases people would rather have it elsewhere (for example, a permalink, title or another unique field). |
@josevalim Ok, so this option will come for the |
It is already in master and we are actively working towards ecto 3.0, so it should be out soon. |
Thanks! |
If a row is already deleted from db Repo.delete raises Ecto.StaleEntryError.
This change docs this for the API.