-
Notifications
You must be signed in to change notification settings - Fork 21.6k
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
Add option to stop swallowing errors on callbacks. #16537
Conversation
@@ -375,6 +363,21 @@ def restore_transaction_record_state(force = false) #:nodoc: | |||
end | |||
end | |||
|
|||
protected |
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.
this code didnt change, just had to move it, so I can have access to clear_transaction_record_state
force_clear_transaction_record_state
restore_transaction_record_state
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.
See above
@chancancode I guess I addressed all your concerns:
|
@@ -3,11 +3,21 @@ module ActiveRecord | |||
module Transactions | |||
extend ActiveSupport::Concern | |||
ACTIONS = [:create, :destroy, :update] | |||
CALLBACK_WARN_MESSAGE = <<-EOF | |||
Currently `config.active_record.raise_in_transactional_callbacks` is set to 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.
I'll start with describing the behavior (i.e. errors are only logged) and the future change. The "option" is really just an opt-in flag and should be mentioned last. (Same for the changelog entry)
But we can also improve this after merging.
Currently, Active Record will rescue any errors raised within after_rollback/after_create callbacks and print them to the logs. Next versions of rails will not rescue those errors anymore, and just bubble them up, as the other callbacks. This adds a opt-in flag to enable that behaviour, of not rescuing the errors. Example: # For not swallow errors in after_commit/after_rollback config.active_record.errors_in_transactional_callbacks = true [fixes rails#13460]
@chancancode Warning message, CHANGELOG, and commit message updated. |
Add option to stop swallowing errors on callbacks.
@@ -63,13 +67,19 @@ def rollback | |||
end | |||
|
|||
def rollback_records | |||
records.uniq.each do |record| | |||
ite = records.uniq |
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.
Is ite
an acronym for something?
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.
iterator
...
Perhaps new apps should be generated with the config option already set? |
@jonleighton yep, it's been added in c7c2df2 (Thanks for taking your time to help review this by the way!) |
By default Rails swallows exception in after_{commit/rollback} hooks, therefore prevent specs to fail. By moving the callbacks inside the transaction in test environment any exceptions thrown will correctly be bubbled up. There is an option to fix that in rails 4.2 rails/rails#16537
See [#14488] [1] and [#16537] [2] for more details. [1]: [rails/rails#14488] [2]: [rails/rails#16537]
See [#14488] and [#16537] for more details. [#14488]: [rails/rails#14488] [#16537]: [rails/rails#16537]
See [#14488] and [#16537] for more details. [#14488]: [rails/rails#14488] [#16537]: [rails/rails#16537]
Seconds take of #14488 .
After the transaction refactor, we can cleanly apply this patch, as we have a better control of the stack of transactions, and we know that even when raising errors, the transaction wont leaky into the stack.
Description
Add option to stop swallowing standard errors on
after_commit
andafter_rollback
.Currently the option will be +false+ and throw a warning untill set it to +true+.
Example:
The option should be removed in future versions of Rails, as the desired
behaviour is not to swallow exceptions.
[fixes #13460]
review @jonleighton @rafaelfranca @tenderlove @chancancode @senny