Skip to content

Do not swallow unknown configuration options for ActiveJob#39472

Merged
rafaelfranca merged 1 commit intorails:masterfrom
fatkodima:activejob-unknown-configs
Dec 1, 2020
Merged

Do not swallow unknown configuration options for ActiveJob#39472
rafaelfranca merged 1 commit intorails:masterfrom
fatkodima:activejob-unknown-configs

Conversation

@fatkodima
Copy link
Member

Problem:

In application.rb I made a mistake

config.active_job.queu_adapter = :sidekiq

And in console I'm seeing:

> Rails.application.config.active_job
=> {:queu_adapter=>:sidekiq, :queue_adapter=>:async}
> ActiveJob::Base.queue_adapter_name
=> "async"

So instead of swallowing nonexistent configs like spelling mistakes and wondering why everything is broken 😄 , it should be helpful to raise an error.

@rails-bot
Copy link

rails-bot bot commented Aug 27, 2020

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Thank you for your contributions.

@rails-bot rails-bot bot added the stale label Aug 27, 2020
@sinsoku
Copy link
Contributor

sinsoku commented Aug 30, 2020

If users had set the wrong option for an app in production env, the app would raise an exception and not start after upgrading Rails.
I thought it would be safer to output a warning instead of raising an exception.

@rails-bot rails-bot bot removed the stale label Aug 30, 2020
@fatkodima
Copy link
Member Author

This reflects other subframeworks behavior, for example

options.each { |k, v| send("#{k}=", v) }

Raising is safer, imo, especially in production, because warning 99% would be unnoticed in logs.

@rails-bot
Copy link

rails-bot bot commented Nov 28, 2020

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Thank you for your contributions.

@rails-bot rails-bot bot added the stale label Nov 28, 2020
@fatkodima
Copy link
Member Author

This is still valid.

@rails-bot rails-bot bot removed the stale label Nov 28, 2020
@rafaelfranca rafaelfranca merged commit a173a65 into rails:master Dec 1, 2020
@georgeclaghorn
Copy link
Contributor

This seems to have broken some Active Job config with eager-loading enabled (queue_name_prefix specifically). Going to revert for now.

Reproduction steps:

  1. Generate a new Rails app based on master.

  2. Add a job that uses queue_as:

    # app/jobs/test_job.rb
    class TestJob < ApplicationJob
      queue_as :baz
    end
  3. Set config.eager_loading and config.cache_classes to true in config/environments/development.rb.

  4. Set config.active_job.queue_name_prefix in development:

    # config/environments/development.rb
    config.active_job.queue_name_prefix = "foo_bar"
  5. spring stop && rails runner "puts TestJob.queue_name"

Expected output: foo_bar_baz. Actual output: baz.

georgeclaghorn added a commit that referenced this pull request Dec 18, 2020
This change broke config.active_job.queue_name_prefix with eager-loading enabled (i.e. in production, by default).

This reverts commit a173a65, reversing
changes made to 89414f5.
@rafaelfranca
Copy link
Member

This is a symptom that Active Job is being loaded earlier than config/environments/development.rb.

@georgeclaghorn
Copy link
Contributor

georgeclaghorn commented Dec 19, 2020

Yeah, that’s the case as far as I could tell. Surprising, but I guess nothing besides AJ queue_as relies on config being set at load time.

@georgeclaghorn
Copy link
Contributor

Er, maybe not. I was only looking at ActiveJob::Base.queue_name_prefix in my testing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants