-
Notifications
You must be signed in to change notification settings - Fork 11.3k
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
[5.1] Exists property is set to false on soft deleted eloquent model #9806
Conversation
|
||
$this->exists = false; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no trailing whitespace please
Wow, I really should call it a day - even the automatic code formatting failed on me thus the trailing spaces. |
Could you rebase to resolve the merge conflcits please. |
Adds integration test for issue #9794
Done. |
@GrahamCampbell I found some other bugs related to the model deletion and the exists property:
Should I add fixes for those to this pull request? |
The return type of |
Thanks for the cross reference! Even though I would discuss this from a different point of view. The forceDelete method (just as the delete method) may fail for whatever reason and without throwing an exception. As a developer you have to know whether this implied 'strong' operation has failed or not, you need the model to be deleted and you need to know if the deletion was successful or not and if you should take any additional action. That being said you may still return void (i.e. not call return) in forceDelete if that's a choice by design but the meaning of this should be very clear and documented. I.e. a omitted return would mean 'I don't know what happened, check for yourself' while a bool value would indicate very clearly the result of the operation on which the developer can rely. 'true' means the deletion operation was successful while 'false' means the operation did nothing due to some kind of error which should be handled by the caller. Btw. there's no such thing as a 'real' void return in PHP. Not calling return is the same as returning NULL (http://php.net/manual/en/functions.returning-values.php) |
Yes, but not the same as void. Returning a string is allowed if the return annotation says void for example. |
True, that's at least the definition of phpdoc.
I don't wanna get offtopic but I guess the point is that you shouldn't return anything if you define the return value as void. Defining a return value as undefined and telling the users to not use it but on the other hand actually returning meaningful and well defined data is unexpected and inconsistent. Why return something if it can't and shouldn't be used anyways? That's crying for wrong usages, misunderstandings and unwanted side effects. Which brings me back to the mentioned methods Question regarding this: what's the current definition and interpretation of the possible return values of the
My suggestion regarding this particular point for a clear and consistent definition and implementation (note that I haven't added those to the pull request yet): Please note that the other previously listed bugs (3, 4 and 5) not necessarily have anything to do with this. Those remain no matter how the definition of the return values look like. Sorry for the TLDR block. |
Should this be considered a breaking change? |
Yeh, this probably needs to go to 5.2. |
The pull request in its current form is not a breaking change but rather a bugfix. I wouldn't recommend to postpone it. Changing the return value behavior of Returning From my point of view the current deletion behavior (maybe except the deleted event firing) should be fixed since 5.1 is meant to be a LTS version which might be used for several years. But that's of course a decision the software architect has to make ;-) How about I open a new separate pull request later for the change of the return value thing so you're actually able to see what would change in code? |
Ping @HolgerW1. |
@HolgerW1 Just to understand... Why you closed this PR? |
Because we're not accepting it on 5.1. We're waiting on a PR to 5.2. |
@GrahamCampbell It isn't considered like a bugfix? Users on 5.1 will be ever affected by this bug on LTS? I don't think that it is a breaking-change, but an expected behaviour when you call Imagine that you have a system with Administrators and Moderators. If some Moderator delete something, they will do a soft delete. Administrators can check if it will be hard deleted or restored (returning to Moderators) or just keep as soft delete. To hard delete in this case, you should use a workaround (nothing good) by restoring first and then forceDeleting. Ok, it's just a example. In this case I should consider create another system like "tag as invalid" to Administrator check if before delete. But is possible you expect that by terms. |
As Graham said, they consider it a breaking change and it seems there was no chance for it to get it in for 5.1. Furthermore even though this PR would fix this specific issue the whole
Sorry, but I currently don't have the time to create a PR for the master branch. Plus I think it would make more sense if someone would review the current deletion implementations. Especially the inconsistent return behavior and the setting of the |
This is fixed in 5.5. |
If you soft delete a model the property exists is set to false which may lead to problems.
Try the following code as a test:
Surprisingly the model won't be hard deleted because the first delete call will set the exists property to false thus the second call of forceDelete won't perform anything and the model remains in the DB.
Soft deleting a model should prevent setting the exists property to false because otherwise the model object is in an inconsistent state and any logic relying on this property to check if a model was deleted will fail.