Skip to content
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

Don't rely on false return from callbacks to halt execution #18456

Conversation

jrafanie
Copy link
Member

We're already using throw :abort, so there's no code for us to change.

This setting is removed in rails 5.1 but will temporarily get rid of this
annoying warning:

DEPRECATION WARNING: Returning `false` in Active Record and Active Model
callbacks will not implicitly halt a callback chain in Rails 5.1. To
explicitly halt the callback chain, please use `throw :abort` instead.
(called from block (3 levels) in <top (required)> at
/home/travis/build/ManageIQ/manageiq/spec/models/miq_task_spec.rb:297)

We're already using throw :abort, so there's no code for us to change.

This setting is removed in rails 5.1 but will temporarily get rid of this
annoying warning:

DEPRECATION WARNING: Returning `false` in Active Record and Active Model
callbacks will not implicitly halt a callback chain in Rails 5.1. To
explicitly halt the callback chain, please use `throw :abort` instead.
(called from block (3 levels) in <top (required)> at
/home/travis/build/ManageIQ/manageiq/spec/models/miq_task_spec.rb:297)
@miq-bot
Copy link
Member

miq-bot commented Feb 13, 2019

Checked commit jrafanie@a8d88d0 with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0
1 file checked, 0 offenses detected
Everything looks fine. 🍰

@jrafanie jrafanie requested a review from kbrock February 20, 2019 22:58
@kbrock
Copy link
Member

kbrock commented Feb 26, 2019

This looks good.

ok, so this is complaining that while check_active and check_associations use raise :abort for the fail cases (good future behavior), the methods also return true for the success case - which is basically a NOP.

Looks like 8 models are using raise :abort (or raise something else) in their before_* :check_* callbacks. I am not able to find any of those callbacks that are still using the legacy return false behavior.

This change (on the rails side) makes me nervous since callbacks have cared about the return value for so long.

Copy link
Member

@kbrock kbrock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jrafanie
Copy link
Member Author

This change (on the rails side) makes me nervous since callbacks have cared about the return value for so long.

Me too but like you, I didn't see anything relying on the return of true or false.

@kbrock kbrock merged commit 55e4924 into ManageIQ:master Feb 26, 2019
@kbrock kbrock added this to the Sprint 106 Ending Mar 4, 2019 milestone Feb 26, 2019
@kbrock kbrock self-assigned this Feb 26, 2019
@jrafanie jrafanie deleted the fix_deprecation_returning_false_in_callbacks_will_not_implicitly_halt branch October 4, 2019 19:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants