This project is archived and is in readonly mode.
after_save callback should not be called if a before_* callback was cancelled
-
Pablo Mercado
I have observed the reported behaviour. The scenario I observed is this: A before_create callback 'cancels' the save; the object is not saved. the after_save callback is still called.
The documentation suggests that the after_save callback would not be called in such a scenario.
I have reviewed the patch; the patch is straight-forward and effective. I also reviewed the test cases; I am glad to see that, with the application of the patch, the cancelling of callback chains is actually tested now (I could not find a test cases for this scenario prior to applying the patch).
-
José Valim
I don't know if this is correct or not.
I think it would break a lot of applications, so if this patch is accepted, at least a deprecation warning should be set.
-
Michael Koziarski
This change is consistent with the documentation so I'm going to apply it.
However I think we'll just put it into 2.3, not a 2.2 point release. This should limit the risk of surprise breakage.
-
Repository
- State changed from new to committed
(from [7a0e7c7270548138a333bc39aab5aec80580174b]) Fixed broken after_save callback; was being called when before_create was canceled or before_update was canceled
Signed-off-by: Michael Koziarski michael@koziarski.com [#1735 after_save callback should not be called if a before_* callback was cancelled state:committed] http://github.com/rails/rails/co...
-
Mathijs Kwik
The description of the bug in the changelog is wrong. Look at the code before the patch, it has: "return false if callback(:before_save) == false" in it. So the case mentioned in the changelog (after save still executing if before_save fails) is wrong.
The problem this patch is trying to fix, is that after_save is being called if a before_create or before_update has cancelled the saving. Not a before_save. That one worked already. This is also the reason why the other before/after callbacks didn't need 'fixing'
