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

Load Parameters configurations on :action_controller only once #30045

Merged
merged 2 commits into from Aug 15, 2017

Conversation

Projects
None yet
7 participants
@albertoalmagro
Contributor

albertoalmagro commented Aug 2, 2017

Summary

This PR fixes the regression where ActionController::UnpermittedParameters exceptions are not being raised.

To accomplish that the following has been made:

  • Allow ActiveSupport::LazyLoadHooks to be executed only once.
    Provide run_once: true option to on_load in case you want a hook only to be executed once. This may be useful in cases where executing a hook several times may have undesired side effects. Example: ActiveSupport.on_load(:action_controller, run_once: true)
  • Load Parameters configurations on :action_controller only once.
    By using the new ActiveSupport::LazyLoadHooksfunctionality described above fixes regression ActionController::UnpermittedParameters not raised. The inner hook was being executed twice, once when ActionController::Base was loaded and again when ActionController::API was loaded. As options.delete operations inside the block are not idempotent, the second time it was run there was no configuration option available.

Other Information

More information can be found in Issue 30025.

@rails-bot

This comment has been minimized.

Show comment
Hide comment
@rails-bot

rails-bot Aug 2, 2017

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @pixeltrix (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

This repository is being automatically checked for code quality issues using Code Climate. You can see results for this analysis in the PR status below. Newly introduced issues should be fixed before a Pull Request is considered ready to review.

Please see the contribution instructions for more information.

rails-bot commented Aug 2, 2017

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @pixeltrix (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

This repository is being automatically checked for code quality issues using Code Climate. You can see results for this analysis in the PR status below. Newly introduced issues should be fixed before a Pull Request is considered ready to review.

Please see the contribution instructions for more information.

Show outdated Hide outdated actionpack/lib/action_controller/railtie.rb
@albertoalmagro

This comment has been minimized.

Show comment
Hide comment
@albertoalmagro

albertoalmagro Aug 3, 2017

Contributor

@rafaelfranca @betesh changes done and PR description updated.

Contributor

albertoalmagro commented Aug 3, 2017

@rafaelfranca @betesh changes done and PR description updated.

@albertoalmagro albertoalmagro changed the title from Load Parameters configurations on :action_controller_base to Load Parameters configurations on :action_controller only once Aug 7, 2017

@rafaelfranca

This is great! I made a commend about the implementation that I think can be simpler.

Show outdated Hide outdated activesupport/lib/active_support/lazy_load_hooks.rb
Show outdated Hide outdated activesupport/lib/active_support/lazy_load_hooks.rb
Show outdated Hide outdated activesupport/lib/active_support/lazy_load_hooks.rb
Show outdated Hide outdated activesupport/lib/active_support/lazy_load_hooks.rb
Show outdated Hide outdated activesupport/lib/active_support/lazy_load_hooks.rb
@albertoalmagro

This comment has been minimized.

Show comment
Hide comment
@albertoalmagro

albertoalmagro Aug 11, 2017

Contributor

@rafaelfranca done, I made methods private and rebased. Thanks!

Contributor

albertoalmagro commented Aug 11, 2017

@rafaelfranca done, I made methods private and rebased. Thanks!

Show outdated Hide outdated activesupport/lib/active_support/lazy_load_hooks.rb

albertoalmagro added some commits Aug 3, 2017

Allow lazy load hooks to be executed only once
Provide run_once: true option to on_load in case you want a hook only to be executed once. This may be useful in cases where executing a hook several times may have undesired side effects
Load Parameters configurations on :action_controller only once
Fixes regression ActionController::UnpermittedParameters not raised. The inner hook was being executed twice, once when ActionController::Base was loaded and again when ActionController::API was loaded. As options.delete operations inside the block are not idempotent, the second time it was run there was no configuration option available
@albertoalmagro

This comment has been minimized.

Show comment
Hide comment
@albertoalmagro

albertoalmagro Aug 14, 2017

Contributor

@kaspth I really like your proposal, I have applied it but changing the method's name to with_execution_control instead of with_once_execution. with_execution_control suggests me that we are doing some control to determine if the hook will be executed or not whereas with_once_execution feels to me like it will always be one single execution.

I have also renamed the option to :run_once because I think it expresses better its intention.

@rafaelfranca please also review last changes.

Contributor

albertoalmagro commented Aug 14, 2017

@kaspth I really like your proposal, I have applied it but changing the method's name to with_execution_control instead of with_once_execution. with_execution_control suggests me that we are doing some control to determine if the hook will be executed or not whereas with_once_execution feels to me like it will always be one single execution.

I have also renamed the option to :run_once because I think it expresses better its intention.

@rafaelfranca please also review last changes.

@rafaelfranca

This comment has been minimized.

Show comment
Hide comment
@rafaelfranca

rafaelfranca Aug 15, 2017

Member

Just to confirm, does the application that you are reproducing this bug has ActionController::Api classes?

Member

rafaelfranca commented Aug 15, 2017

Just to confirm, does the application that you are reproducing this bug has ActionController::Api classes?

@rafaelfranca rafaelfranca merged commit c171890 into rails:master Aug 15, 2017

2 checks passed

codeclimate All good!
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

rafaelfranca added a commit that referenced this pull request Aug 15, 2017

Merge pull request #30045 from albertoalmagro/fix-raise-unpermitted-p…
…arameters-regression

Load Parameters configurations on :action_controller only once
@albertoalmagro

This comment has been minimized.

Show comment
Hide comment
@albertoalmagro

albertoalmagro Aug 15, 2017

Contributor

Yes @rafaelfranca , I can confirm it. I have debugged it and I see how the hook is registered for both ActionController::Base and ActionController::API. I have also created a Rails app using this branch and reproduced the bug without using :run_once. After adding :run_once the problem is solved 😄

Contributor

albertoalmagro commented Aug 15, 2017

Yes @rafaelfranca , I can confirm it. I have debugged it and I see how the hook is registered for both ActionController::Base and ActionController::API. I have also created a Rails app using this branch and reproduced the bug without using :run_once. After adding :run_once the problem is solved 😄

rafaelfranca added a commit that referenced this pull request Aug 15, 2017

Merge pull request #30045 from albertoalmagro/fix-raise-unpermitted-p…
…arameters-regression

Load Parameters configurations on :action_controller only once
end
def execute_hook(base, options, block)
with_execution_control(name, block, options[:run_once]) do

This comment has been minimized.

@kaspth

kaspth Aug 16, 2017

Member

Where is name coming from here? Previously execute_hook was changed to pass it in.

@kaspth

kaspth Aug 16, 2017

Member

Where is name coming from here? Previously execute_hook was changed to pass it in.

This comment has been minimized.

@albertoalmagro

albertoalmagro Aug 16, 2017

Contributor

Good catch @kaspth I wonder why tests didn't blow up. Since this is merged, please tell me how should I fix it?

@albertoalmagro

albertoalmagro Aug 16, 2017

Contributor

Good catch @kaspth I wonder why tests didn't blow up. Since this is merged, please tell me how should I fix it?

This comment has been minimized.

@albertoalmagro

albertoalmagro Aug 16, 2017

Contributor

@kaspth I already have a branch to pass the name. Should I open a new PR and reference this one?

@albertoalmagro

albertoalmagro Aug 16, 2017

Contributor

@kaspth I already have a branch to pass the name. Should I open a new PR and reference this one?

This comment has been minimized.

@rafaelfranca

rafaelfranca Aug 16, 2017

Member

Yes please

@rafaelfranca

rafaelfranca Aug 16, 2017

Member

Yes please

This comment has been minimized.

@albertoalmagro

albertoalmagro Aug 16, 2017

Contributor

@rafaelfranca @kaspth Done please check PR #30285

@albertoalmagro

albertoalmagro Aug 16, 2017

Contributor

@rafaelfranca @kaspth Done please check PR #30285

redtachyons added a commit to redtachyons/merit that referenced this pull request Nov 3, 2017

Rails execute `action_controller` onload hooks for Both ActionControl…
…ler::Base and ActionController::API.

Rails [introduced](rails/rails#30045) `has_one` option to limit executions to one

This will fix #173 for rails 5.1.4 and above

redtachyons pushed a commit to redtachyons/merit that referenced this pull request Nov 3, 2017

Run action controller load hook only once
Rails execute `action_controller` onload hooks for Both ActionController::Base and ActionController::API.

Rails [introduced](rails/rails#30045) `has_one` option to limit executions to one

This will fix #173 for rails 5.1.4 and above
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment