"No setting named __ exists" when trying to run specs on poll plugin

Hi,

I’m making a plugin and am trying to write some tests, but when I try to run the specs of poll plugin via

bundle exec rake plugin:spec poll

as seen here, I’m getting this error:

An error occurred while loading ./plugins/poll/spec/integration/poll_endpoints_spec.rb.
Failure/Error: raise ArgumentError.new(“No setting named ‘#{name}’ exists”)

ArgumentError:
  No setting named 'discourse_narrative_bot_enabled' exists
# ./lib/site_settings/defaults_provider.rb:58:in `set_regardless_of_locale'
# ./config/environments/test.rb:74:in `block (3 levels) in <main>'
# ./config/environments/test.rb:63:in `tap'
# ./config/environments/test.rb:63:in `block (2 levels) in <main>'
# /Users/myUser/.rvm/gems/ruby-2.7.0/gems/activesupport-6.1.3.2/lib/active_support/lazy_load_hooks.rb:68:in `block in execute_hook'
# /Users/myUser/.rvm/gems/ruby-2.7.0/gems/activesupport-6.1.3.2/lib/active_support/lazy_load_hooks.rb:61:in `with_execution_control'
# /Users/myUser/.rvm/gems/ruby-2.7.0/gems/activesupport-6.1.3.2/lib/active_support/lazy_load_hooks.rb:66:in `execute_hook'
# /Users/myUser/.rvm/gems/ruby-2.7.0/gems/activesupport-6.1.3.2/lib/active_support/lazy_load_hooks.rb:52:in `block in run_load_hooks'
# /Users/myUser/.rvm/gems/ruby-2.7.0/gems/activesupport-6.1.3.2/lib/active_support/lazy_load_hooks.rb:51:in `each'
# /Users/myUser/.rvm/gems/ruby-2.7.0/gems/activesupport-6.1.3.2/lib/active_support/lazy_load_hooks.rb:51:in `run_load_hooks'
# /Users/myUser/.rvm/gems/ruby-2.7.0/gems/railties-6.1.3.2/lib/rails/application/finisher.rb:140:in `block in <module:Finisher>'
# /Users/myUser/.rvm/gems/ruby-2.7.0/gems/railties-6.1.3.2/lib/rails/initializable.rb:32:in `instance_exec'
# /Users/myUser/.rvm/gems/ruby-2.7.0/gems/railties-6.1.3.2/lib/rails/initializable.rb:32:in `run'
# /Users/myUser/.rvm/gems/ruby-2.7.0/gems/railties-6.1.3.2/lib/rails/initializable.rb:61:in `block in run_initializers'
# /Users/myUser/.rvm/gems/ruby-2.7.0/gems/railties-6.1.3.2/lib/rails/initializable.rb:60:in `run_initializers'
# /Users/myUser/.rvm/gems/ruby-2.7.0/gems/railties-6.1.3.2/lib/rails/application.rb:384:in `initialize!'
# /Users/myUser/.rvm/gems/ruby-2.7.0/gems/railties-6.1.3.2/lib/rails/railtie.rb:207:in `public_send'
# /Users/myUser/.rvm/gems/ruby-2.7.0/gems/railties-6.1.3.2/lib/rails/railtie.rb:207:in `method_missing'
# ./config/environment.rb:7:in `<top (required)>'
# ./spec/rails_helper.rb:56:in `require'
# ./spec/rails_helper.rb:56:in `<top (required)>'
# ./plugins/poll/spec/integration/poll_endpoints_spec.rb:3:in `require'
# ./plugins/poll/spec/integration/poll_endpoints_spec.rb:3:in `<top (required)>'

What am I doing wrong when trying to run the poll plugin’s tests? Why would this particular setting not be loaded to the default locale?

Thanks.

To run just the poll specs the command is: bundle exec rake "plugin:spec[poll]" (or shorter: bin/rake "plugin:spec[poll]") otherwise you’re running all plugins specs.

Regarding the error you’re getting, I’m not sure. Is the test database migrated? (bin/rails db:migrate RAILS_ENV=test)

2 Likes

Thanks. Like you said, it did run all the plugin specs, which I worked around by removing the other plugins. I was basing off of this, but it turns out the parentheses were in the wrong spot.

Yes, the database is migrated in the test environment. I worked around this error by commenting out the raise ArgumentError.new("No setting named '#{name}' exists") line and replacing it with a puts, and it shows only discourse_narrative_bot_enabled triggers this error; all other settings are fine. I don’t think we did anything with this setting. Anyway, since my spec run properly while ignoring this error, I can leave the workaround in my local discourse. When I find what actually caused this, I’ll update this post.

1 Like

I’m currently getting this exact error in CI when attempting to run the migrations on the database:

Run bin/rake db:create
rake aborted!
ArgumentError: No setting named 'discourse_narrative_bot_enabled' exists
/home/runner/work/discourse-multilingual/discourse-multilingual/lib/site_settings/defaults_provider.rb:58:in `set_regardless_of_locale'
/home/runner/work/discourse-multilingual/discourse-multilingual/config/environments/test.rb:73:in `block (3 levels) in <main>'
/home/runner/work/discourse-multilingual/discourse-multilingual/config/environments/test.rb:63:in `tap'
/home/runner/work/discourse-multilingual/discourse-multilingual/config/environments/test.rb:63:in `block (2 levels) in <main>'
/home/runner/work/discourse-multilingual/discourse-multilingual/vendor/bundle/ruby/2.7.0/gems/activesupport-7.0.3.1/lib/active_support/lazy_load_hooks.rb:79:in `block in execute_hook'
/home/runner/work/discourse-multilingual/discourse-multilingual/vendor/bundle/ruby/2.7.0/gems/activesupport-7.0.3.1/lib/active_support/lazy_load_hooks.rb:72:in `with_execution_control'
/home/runner/work/discourse-multilingual/discourse-multilingual/vendor/bundle/ruby/2.7.0/gems/activesupport-7.0.3.1/lib/active_support/lazy_load_hooks.rb:77:in `execute_hook'
/home/runner/work/discourse-multilingual/discourse-multilingual/vendor/bundle/ruby/2.7.0/gems/activesupport-7.0.3.1/lib/active_support/lazy_load_hooks.rb:63:in `block in run_load_hooks'
/home/runner/work/discourse-multilingual/discourse-multilingual/vendor/bundle/ruby/2.7.0/gems/activesupport-7.0.3.1/lib/active_support/lazy_load_hooks.rb:62:in `each'
/home/runner/work/discourse-multilingual/discourse-multilingual/vendor/bundle/ruby/2.7.0/gems/activesupport-7.0.3.1/lib/active_support/lazy_load_hooks.rb:62:in `run_load_hooks'
/home/runner/work/discourse-multilingual/discourse-multilingual/vendor/bundle/ruby/2.7.0/gems/railties-7.0.3.1/lib/rails/application/finisher.rb:87:in `block in <module:Finisher>'
/home/runner/work/discourse-multilingual/discourse-multilingual/vendor/bundle/ruby/2.7.0/gems/railties-7.0.3.1/lib/rails/initializable.rb:32:in `instance_exec'
/home/runner/work/discourse-multilingual/discourse-multilingual/vendor/bundle/ruby/2.7.0/gems/railties-7.0.3.1/lib/rails/initializable.rb:32:in `run'
/home/runner/work/discourse-multilingual/discourse-multilingual/vendor/bundle/ruby/2.7.0/gems/railties-7.0.3.1/lib/rails/initializable.rb:61:in `block in run_initializers'
/home/runner/work/discourse-multilingual/discourse-multilingual/vendor/bundle/ruby/2.7.0/gems/railties-7.0.3.1/lib/rails/initializable.rb:60:in `run_initializers'
/home/runner/work/discourse-multilingual/discourse-multilingual/vendor/bundle/ruby/2.7.0/gems/railties-7.0.3.1/lib/rails/application.rb:372:in `initialize!'
/home/runner/work/discourse-multilingual/discourse-multilingual/config/environment.rb:7:in `<main>'
/home/runner/work/discourse-multilingual/discourse-multilingual/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.13.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
/home/runner/work/discourse-multilingual/discourse-multilingual/vendor/bundle/ruby/2.7.0/gems/bootsnap-1.13.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
/home/runner/work/discourse-multilingual/discourse-multilingual/vendor/bundle/ruby/2.7.0/gems/zeitwerk-2.6.0/lib/zeitwerk/kernel.rb:35:in `require'
/home/runner/work/discourse-multilingual/discourse-multilingual/vendor/bundle/ruby/2.7.0/gems/railties-7.0.3.1/lib/rails/application.rb:348:in `require_environment!'
/home/runner/work/discourse-multilingual/discourse-multilingual/vendor/bundle/ruby/2.7.0/gems/railties-7.0.3.1/lib/rails/application.rb:511:in `block in run_tasks_blocks'
Tasks: TOP => db:migrate => db:load_config => environment
(See full trace by running task with --trace)
Error: Process completed with exit code 1.

Seems to be caused by this line in core:

1 Like

Team, this is killing me.

Our CI is breaking on db:migrate because of this.

It is almost verbatim a copy of the CI for the discourse-chat plugin, but with the addition of a cron schedule.

Our CI works for PR’s and commits, but on cron job it’s failing here every time.

I’m able to reproduce this on the rails console by a similar block:

[19] pry(main)> SiteSetting.defaults.tap do |s|
[19] pry(main)*   s.set_regardless_of_locale(:discourse_narrative_bot_enab, false)
[19] pry(main)* end
ArgumentError: No setting named 'discourse_narrative_bot_enab' exists

This works if I put:

[21] pry(main)> SiteSetting.defaults.tap do |s|
[21] pry(main)*   if s.has_setting? :discourse_narrative_bot_enab
[21] pry(main)*     s.set_regardless_of_locale(:discourse_narrative_bot_enab, false)
[21] pry(main)*   end
[21] pry(main)* end

and just to check, fails with:

[21] pry(main)> SiteSetting.defaults.tap do |s|
[21] pry(main)*   if s.has_setting? :discourse_narrative_bot_enabled
[21] pry(main)*     s.set_regardless_of_locale(:discourse_narrative_bot_enab, false)
[21] pry(main)*   end
[21] pry(main)* end

So I propose the following change in a PR which I’d be happy to submit:

 if ENV['LOAD_PLUGINS'] == '1' && s.has_setting? :discourse_narrative_bot_enabled

For some reason the presence of the narrative bot plugin can’t be guaranteed?

In these examples you have the site setting as discourse_narrative_bot_enab, not discourse_narrative_bot_enabled. I’m guessing once that’s corrected, it’s not reproducable?

The most surprising thing here is:

That suggests a difference in the runtime environment for the scheduled runs :thinking:

Looking at one of the fail logs it seems like GitHub is cloning the multilingual plugin directly into the plugins directory, rather than into its own directory. So it’s essentially ‘uninstalling’ all the core plugins (and failing to install itself properly)

I suspect, to make cron work, we’ll need to replace all the occurences of github.event.repository.name with something else:

Looking at the docs, it doesn’t look like there’s a consistent way to get the repository name (without the owner), so we’ll need some trickery. I think this should do it:

cc @CvX - maybe we should use this technique in the plugin/theme template CI?

2 Likes

This was deliberate to force an error (and handle it).

Oooh gosh, good catch thanks!

2 Likes

merged, thanks so much @David that was very kind of you.

Definitely :beers: on me if I’m ever in your area! :slight_smile:

2 Likes

FYI cron tests just ran perfectly thanks again.:tada:

1 Like

@CvX just shared this article with me:

So the hacky repository-name workaround shouldn’t be required any more for cron jobs :tada: cc @merefield

1 Like