Skip to content

Commit

Permalink
Merge pull request #33880 from robbertbrak/master
Browse files Browse the repository at this point in the history
Clarify transactional behavior of after_commit and after_rollback callbacks

[ci skip]
  • Loading branch information
kamipo committed Sep 28, 2018
2 parents d32d5c6 + 0a65792 commit 71030c9
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion guides/source/active_record_callbacks.md
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,9 @@ class PictureFile < ApplicationRecord
end
```

WARNING. The `after_commit` and `after_rollback` callbacks are called for all models created, updated, or destroyed within a transaction block. However, if an exception is raised within one of these callbacks, the exception will bubble up and any remaining `after_commit` or `after_rollback` methods will _not_ be executed. As such, if your callback code could raise an exception, you'll need to rescue it and handle it within the callback in order to allow other callbacks to run.
WARNING. When a transaction completes, the `after_commit` or `after_rollback` callbacks are called for all models created, updated, or destroyed within that transaction. However, if an exception is raised within one of these callbacks, the exception will bubble up and any remaining `after_commit` or `after_rollback` methods will _not_ be executed. As such, if your callback code could raise an exception, you'll need to rescue it and handle it within the callback in order to allow other callbacks to run.

WARNING. The code executed within `after_commit` or `after_rollback` callbacks is itself not enclosed within a transaction.

WARNING. Using both `after_create_commit` and `after_update_commit` in the same model will only allow the last callback defined to take effect, and will override all others.

Expand Down

0 comments on commit 71030c9

Please sign in to comment.