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

return_false_on_aborted_enqueue setting not working #37030

Closed
paul opened this issue Aug 23, 2019 · 2 comments
Closed

return_false_on_aborted_enqueue setting not working #37030

paul opened this issue Aug 23, 2019 · 2 comments

Comments

@paul
Copy link
Contributor

paul commented Aug 23, 2019

Steps to reproduce

I'm attempting to upgrade a 5.2 app to 6.0. I get about a million warnings during the spec suite:

DEPRECATION WARNING: Rails 6.1 will return false when the enqueuing is aborted. Make sure your code doesn't depend on it returning the instance of the job and set config.active_job.return_false_on_aborted_enqueue = true to remove the deprecations. (called from handle_timeout at /home/rando/Code/textus/tesseract/app/jobs/deliver_message_job.rb:49)

Since, as far as I'm aware, we never rely on the return value of enqueuing a job, I uncommented the setting in new_framework_defaults_6_0.rb

Rails.application.config.active_job.return_false_on_aborted_enqueue = true

This did not make the warnings go away.

Expected behavior

No warnings after enabling active_job.return_false_on_aborted_enqueue = true

Actual behavior

Tons of warnings.

It seems the Rails config setting isn't getting passed to the ActiveJob class variable:

$ rails c
[tesseract|development|main]> Rails.application.config.active_job.return_false_on_aborted_enqueue
=> true
[tesseract|development|main]> ActiveJob::Base.return_false_on_aborted_enqueue
=> false
[tesseract|development|main]> ApplicationJob.return_false_on_aborted_enqueue
=> false

System configuration

Rails version: 6.0

Ruby version: 2.6.3

@eugeneius
Copy link
Member

This could be happening because your application is loading Active Job too early; the values in Rails.application.config.active_job are applied to ActiveJob::Base as soon as it loads, so if that happens before config/initializers/new_framework_defaults_6_0.rb runs it has no effect:

ActiveSupport.on_load(:active_job) do
options.each do |k, v|
k = "#{k}="
send(k, v) if respond_to? k
end
end

You can confirm this by adding ActiveSupport.on_load(:active_job) { puts caller } to config/application.rb, adding puts "applying new framework defaults" to config/initializers/new_framework_defaults_6_0.rb, and checking whether the stacktrace is printed before the message. If it is, it should help you to find the offending code in your application.

@paul
Copy link
Contributor Author

paul commented Aug 24, 2019

@eugeneius make sense, thanks. Looks like its not something I have any control over, the Bundler.require line in application.rb loads the Chewy gem, which triggers loading ActiveJob.

If anyone comes across this issue with the same problem, I solved it by adding this to my config/initializers/new_framework_defaults_6_0.rb:

# config/initializers/new_framework_defaults_6_0.rb

# ... snip ...

# Return false instead of self when enqueuing is aborted from a callback.
Rails.application.config.active_job.return_false_on_aborted_enqueue = true

# The above setting seems to have no effect.
# https://github.com/rails/rails/issues/37030
ActiveJob::Base.return_false_on_aborted_enqueue = true

# ... snip ...

Backtrace from ActiveSupport.on_load(:active_job) { puts caller } in application.rb:

/home/rando/.gem/ruby/2.6.3/gems/activesupport-6.0.0/lib/active_support/lazy_load_hooks.rb:72:in `class_eval'
/home/rando/.gem/ruby/2.6.3/gems/activesupport-6.0.0/lib/active_support/lazy_load_hooks.rb:72:in `block in execute_hook'
/home/rando/.gem/ruby/2.6.3/gems/activesupport-6.0.0/lib/active_support/lazy_load_hooks.rb:62:in `with_execution_control'
/home/rando/.gem/ruby/2.6.3/gems/activesupport-6.0.0/lib/active_support/lazy_load_hooks.rb:67:in `execute_hook'
/home/rando/.gem/ruby/2.6.3/gems/activesupport-6.0.0/lib/active_support/lazy_load_hooks.rb:52:in `block in run_load_hooks'
/home/rando/.gem/ruby/2.6.3/gems/activesupport-6.0.0/lib/active_support/lazy_load_hooks.rb:51:in `each'
/home/rando/.gem/ruby/2.6.3/gems/activesupport-6.0.0/lib/active_support/lazy_load_hooks.rb:51:in `run_load_hooks'
/home/rando/.gem/ruby/2.6.3/gems/activejob-6.0.0/lib/active_job/base.rb:74:in `<class:Base>'
/home/rando/.gem/ruby/2.6.3/gems/activejob-6.0.0/lib/active_job/base.rb:61:in `<module:ActiveJob>'
/home/rando/.gem/ruby/2.6.3/gems/activejob-6.0.0/lib/active_job/base.rb:15:in `<main>'
/home/rando/.gem/ruby/2.6.3/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
/home/rando/.gem/ruby/2.6.3/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
/home/rando/.gem/ruby/2.6.3/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/home/rando/.gem/ruby/2.6.3/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
/home/rando/.gem/ruby/2.6.3/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
/home/rando/.gem/ruby/2.6.3/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:325:in `block in require'
/home/rando/.gem/ruby/2.6.3/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:291:in `load_dependency'
/home/rando/.gem/ruby/2.6.3/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:325:in `require'
/home/rando/.gem/ruby/2.6.3/gems/chewy-5.0.0/lib/chewy/strategy/active_job.rb:13:in `<class:ActiveJob>'
/home/rando/.gem/ruby/2.6.3/gems/chewy-5.0.0/lib/chewy/strategy/active_job.rb:12:in `<class:Strategy>'
/home/rando/.gem/ruby/2.6.3/gems/chewy-5.0.0/lib/chewy/strategy/active_job.rb:2:in `<module:Chewy>'
/home/rando/.gem/ruby/2.6.3/gems/chewy-5.0.0/lib/chewy/strategy/active_job.rb:1:in `<main>'
/home/rando/.gem/ruby/2.6.3/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
/home/rando/.gem/ruby/2.6.3/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
/home/rando/.gem/ruby/2.6.3/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/home/rando/.gem/ruby/2.6.3/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
/home/rando/.gem/ruby/2.6.3/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
/home/rando/.gem/ruby/2.6.3/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:325:in `block in require'
/home/rando/.gem/ruby/2.6.3/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:291:in `load_dependency'
/home/rando/.gem/ruby/2.6.3/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:325:in `require'
/home/rando/.gem/ruby/2.6.3/gems/chewy-5.0.0/lib/chewy/strategy.rb:29:in `<main>'
/home/rando/.gem/ruby/2.6.3/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
/home/rando/.gem/ruby/2.6.3/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
/home/rando/.gem/ruby/2.6.3/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/home/rando/.gem/ruby/2.6.3/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
/home/rando/.gem/ruby/2.6.3/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
/home/rando/.gem/ruby/2.6.3/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:325:in `block in require'
/home/rando/.gem/ruby/2.6.3/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:291:in `load_dependency'
/home/rando/.gem/ruby/2.6.3/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:325:in `require'
/home/rando/.gem/ruby/2.6.3/gems/chewy-5.0.0/lib/chewy.rb:53:in `<main>'
/home/rando/.gem/ruby/2.6.3/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
/home/rando/.gem/ruby/2.6.3/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
/home/rando/.gem/ruby/2.6.3/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/home/rando/.gem/ruby/2.6.3/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
/home/rando/.gem/ruby/2.6.3/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
/home/rando/.gem/ruby/2.6.3/gems/bundler-2.0.2/lib/bundler/runtime.rb:81:in `block (2 levels) in require'
/home/rando/.gem/ruby/2.6.3/gems/bundler-2.0.2/lib/bundler/runtime.rb:76:in `each'
/home/rando/.gem/ruby/2.6.3/gems/bundler-2.0.2/lib/bundler/runtime.rb:76:in `block in require'
/home/rando/.gem/ruby/2.6.3/gems/bundler-2.0.2/lib/bundler/runtime.rb:65:in `each'
/home/rando/.gem/ruby/2.6.3/gems/bundler-2.0.2/lib/bundler/runtime.rb:65:in `require'
/home/rando/.gem/ruby/2.6.3/gems/bundler-2.0.2/lib/bundler.rb:114:in `require'
/home/rando/Code/textus/tesseract/config/application.rb:23:in `<main>'
/home/rando/.gem/ruby/2.6.3/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
/home/rando/.gem/ruby/2.6.3/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
/home/rando/.gem/ruby/2.6.3/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/home/rando/.gem/ruby/2.6.3/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
/home/rando/.gem/ruby/2.6.3/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
/home/rando/.gem/ruby/2.6.3/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:325:in `block in require'
/home/rando/.gem/ruby/2.6.3/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:291:in `load_dependency'
/home/rando/.gem/ruby/2.6.3/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:325:in `require'
/home/rando/.gem/ruby/2.6.3/gems/railties-6.0.0/lib/rails/command/actions.rb:22:in `require_application!'
/home/rando/.gem/ruby/2.6.3/gems/railties-6.0.0/lib/rails/command/actions.rb:14:in `require_application_and_environment!'
/home/rando/.gem/ruby/2.6.3/gems/railties-6.0.0/lib/rails/commands/console/console_command.rb:101:in `perform'
/home/rando/.gem/ruby/2.6.3/gems/thor-0.20.3/lib/thor/command.rb:27:in `run'
/home/rando/.gem/ruby/2.6.3/gems/thor-0.20.3/lib/thor/invocation.rb:126:in `invoke_command'
/home/rando/.gem/ruby/2.6.3/gems/thor-0.20.3/lib/thor.rb:387:in `dispatch'
/home/rando/.gem/ruby/2.6.3/gems/railties-6.0.0/lib/rails/command/base.rb:65:in `perform'
/home/rando/.gem/ruby/2.6.3/gems/railties-6.0.0/lib/rails/command.rb:46:in `invoke'
/home/rando/.gem/ruby/2.6.3/gems/railties-6.0.0/lib/rails/commands.rb:18:in `<main>'
/home/rando/.gem/ruby/2.6.3/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
/home/rando/.gem/ruby/2.6.3/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
/home/rando/.gem/ruby/2.6.3/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/home/rando/.gem/ruby/2.6.3/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
/home/rando/.gem/ruby/2.6.3/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
/home/rando/.gem/ruby/2.6.3/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:325:in `block in require'
/home/rando/.gem/ruby/2.6.3/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:291:in `load_dependency'
/home/rando/.gem/ruby/2.6.3/gems/activesupport-6.0.0/lib/active_support/dependencies.rb:325:in `require'
./bin/rails:6:in `<main>'

jsugarman added a commit to ministryofjustice/Claim-for-Crown-Court-Defence that referenced this issue Jul 19, 2021
`cache_versioning` setting is not taking effect since it appears
that govuk_notify_rails is causing early rails loading and
causing it to be "lost".

This is a workaround for issue rails/rails#39855 (comment)
suggested by this issue comment rails/rails#37030 (comment)
jsugarman added a commit to ministryofjustice/Claim-for-Crown-Court-Defence that referenced this issue Jul 19, 2021
NOTE: this setting is not currently taking effect since it appears
that govuk_notify_rails is causing early rails loading and
causing it to be "lost".

This is a workaround for issue rails/rails#39855 (comment)
suggested by this issue comment rails/rails#37030 (comment)
and this activerecord specific issue rails/rails#27844
jsugarman added a commit to ministryofjustice/Claim-for-Crown-Court-Defence that referenced this issue Jul 19, 2021
NOTE: this setting is not taking effect since it appears
that govuk_notify_rails is causing early rails loading and
causing it to be "lost".

This is a workaround for issue rails/rails#39855 (comment)
suggested by this issue comment rails/rails#37030 (comment)
jsugarman added a commit to ministryofjustice/Claim-for-Crown-Court-Defence that referenced this issue Jul 19, 2021
NOTE: this setting is not taking effect since it appears
that govuk_notify_rails is causing early rails loading and
causing it to be "lost".

This is a workaround for issue rails/rails#39855 (comment)
suggested by this issue comment rails/rails#37030 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants