Project

General

Profile

Bug #2343

app/models/setting.rb#default chokes on nil attributes

Added by David Schmitt over 6 years ago. Updated over 6 years ago.

Status:
Closed
Priority:
Normal
Category:
-
Target version:
Difficulty:
Triaged:
No
Bugzilla link:
Pull request:
Fixed in Releases:
Found in Releases:

Description

On a freshly installed wheezy with the 1.1.1+debian1 packages from deb.theforeman.org, I get the following trace:

rake aborted!
can't convert nil into String
/usr/lib/ruby/1.9.1/psych.rb:203:in `parse'
/usr/lib/ruby/1.9.1/psych.rb:203:in `parse_stream'
/usr/lib/ruby/1.9.1/psych.rb:151:in `parse'
/usr/lib/ruby/1.9.1/psych.rb:127:in `load'
/usr/share/foreman/app/models/setting.rb:77:in `default'
/usr/share/foreman/app/models/setting.rb:63:in `value='
/usr/share/foreman/vendor/ruby/1.9.1/gems/activerecord-3.0.20/lib/active_record/base.rb:1569:in `block in attributes='
/usr/share/foreman/vendor/ruby/1.9.1/gems/activerecord-3.0.20/lib/active_record/base.rb:1565:in `each'
/usr/share/foreman/vendor/ruby/1.9.1/gems/activerecord-3.0.20/lib/active_record/base.rb:1565:in `attributes='
/usr/share/foreman/vendor/ruby/1.9.1/gems/activerecord-3.0.20/lib/active_record/base.rb:1416:in `initialize'
/usr/share/foreman/vendor/ruby/1.9.1/gems/activerecord-3.0.20/lib/active_record/validations.rb:32:in `new'
/usr/share/foreman/vendor/ruby/1.9.1/gems/activerecord-3.0.20/lib/active_record/validations.rb:32:in `create!'
/usr/share/foreman/lib/foreman/default_settings/loader.rb:21:in `create'
/usr/share/foreman/lib/foreman/default_settings/loader.rb:77:in `block (2 levels) in load'
/usr/share/foreman/lib/foreman/default_settings/loader.rb:61:in `each'
/usr/share/foreman/lib/foreman/default_settings/loader.rb:61:in `block in load'
/usr/share/foreman/vendor/ruby/1.9.1/gems/activerecord-3.0.20/lib/active_record/connection_adapters/abstract/database_statements.rb:139:in `transaction'
/usr/share/foreman/vendor/ruby/1.9.1/gems/activerecord-3.0.20/lib/active_record/transactions.rb:207:in `transaction'
/usr/share/foreman/lib/foreman/default_settings/loader.rb:33:in `load'
/usr/share/foreman/config/initializers/foreman.rb:4:in `<top (required)>'
/usr/share/foreman/vendor/ruby/1.9.1/gems/activesupport-3.0.20/lib/active_support/dependencies.rb:236:in `load'
/usr/share/foreman/vendor/ruby/1.9.1/gems/activesupport-3.0.20/lib/active_support/dependencies.rb:236:in `block in load'
/usr/share/foreman/vendor/ruby/1.9.1/gems/activesupport-3.0.20/lib/active_support/dependencies.rb:227:in `load_dependency'
/usr/share/foreman/vendor/ruby/1.9.1/gems/activesupport-3.0.20/lib/active_support/dependencies.rb:236:in `load'
/usr/share/foreman/vendor/ruby/1.9.1/gems/railties-3.0.20/lib/rails/engine.rb:201:in `block (2 levels) in <class:Engine>'
/usr/share/foreman/vendor/ruby/1.9.1/gems/railties-3.0.20/lib/rails/engine.rb:200:in `each'
/usr/share/foreman/vendor/ruby/1.9.1/gems/railties-3.0.20/lib/rails/engine.rb:200:in `block in <class:Engine>'
/usr/share/foreman/vendor/ruby/1.9.1/gems/railties-3.0.20/lib/rails/initializable.rb:25:in `instance_exec'
/usr/share/foreman/vendor/ruby/1.9.1/gems/railties-3.0.20/lib/rails/initializable.rb:25:in `run'
/usr/share/foreman/vendor/ruby/1.9.1/gems/railties-3.0.20/lib/rails/initializable.rb:50:in `block in run_initializers'
/usr/share/foreman/vendor/ruby/1.9.1/gems/railties-3.0.20/lib/rails/initializable.rb:49:in `each'
/usr/share/foreman/vendor/ruby/1.9.1/gems/railties-3.0.20/lib/rails/initializable.rb:49:in `run_initializers'
/usr/share/foreman/vendor/ruby/1.9.1/gems/railties-3.0.20/lib/rails/application.rb:134:in `initialize!'
/usr/share/foreman/vendor/ruby/1.9.1/gems/railties-3.0.20/lib/rails/application.rb:77:in `method_missing'
/usr/share/foreman/config/environment.rb:5:in `<top (required)>'
[...]

I've added debugging to the "default" method and it dies with "modulepath is nil".

Returning nil instead of raising an exception let the db:migrate run through.


Related issues

Related to Foreman - Refactor #2660: Setting model, improve tests, string parsing and change to create!Closed2013-06-12
Related to Foreman - Bug #2686: foreman-config doesn't change boolean settingsClosed2013-06-20
Has duplicate Foreman - Bug #3472: "instance of IO needed" failure on new installDuplicate2013-10-22

Associated revisions

Revision 911d3f5c (diff)
Added by Tomáš Strachota over 6 years ago

fixes #2343 - override default settings with custom values

- added check for nil before attribute 'default' is loaded from yaml
- removed logic that tried to set 'value' attr to nil when it was equal to 'default';
it didn't behave predictably as 'default' can be assigned after 'value'

Revision ec57fff6 (diff)
Added by Tomáš Strachota over 6 years ago

fixes #2343 - override default settings with custom values

- added check for nil before attribute 'default' is loaded from yaml
- removed logic that tried to set 'value' attr to nil when it was equal to 'default';
it didn't behave predictably as 'default' can be assigned after 'value'
(cherry picked from commit 911d3f5c8f68d7a6daf89296b92af37d546ce95a)

History

#1 Updated by Dominic Cleal over 6 years ago

  • Status changed from New to Feedback

I'm struggling to work out how this happened, since modulepath has a fixed string as a default.

Are you able to check that default is initialised here? lib/foreman/default_settings/loader.rb:21:in `create'

#2 Updated by David Schmitt over 6 years ago

So, I finally got around to digging deeper into this issue. After playing around with the issue, I noticed that it does not hang on the specific setting, but I can trigger it by setting the value in the settings.yaml. e.g. adding ":administrator: " there, leads to this trace (line numbers may be fuzzy due to debug puts):

foreman@puppetmaster:~$ RAILS_ENV=production rake db:migrate --trace
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
{:name=>"administrator", :value=>"foo@example.com", :description=>"The default administrator email address", :default=>"root@example.org", :category=>"General"}
reading administrator's default: nil
rake aborted!
can't convert nil into String
/usr/lib/ruby/1.9.1/psych.rb:203:in `parse'
/usr/lib/ruby/1.9.1/psych.rb:203:in `parse_stream'
/usr/lib/ruby/1.9.1/psych.rb:151:in `parse'
/usr/lib/ruby/1.9.1/psych.rb:127:in `load'
/usr/share/foreman/app/models/setting.rb:78:in `default'
/usr/share/foreman/app/models/setting.rb:63:in `value='
/usr/share/foreman/vendor/ruby/1.9.1/gems/activerecord-3.0.20/lib/active_record/base.rb:1569:in `block in attributes='
/usr/share/foreman/vendor/ruby/1.9.1/gems/activerecord-3.0.20/lib/active_record/base.rb:1565:in `each'
/usr/share/foreman/vendor/ruby/1.9.1/gems/activerecord-3.0.20/lib/active_record/base.rb:1565:in `attributes='
/usr/share/foreman/vendor/ruby/1.9.1/gems/activerecord-3.0.20/lib/active_record/base.rb:1416:in `initialize'
/usr/share/foreman/vendor/ruby/1.9.1/gems/activerecord-3.0.20/lib/active_record/validations.rb:32:in `new'
/usr/share/foreman/vendor/ruby/1.9.1/gems/activerecord-3.0.20/lib/active_record/validations.rb:32:in `create!'
/usr/share/foreman/lib/foreman/default_settings/loader.rb:22:in `create'
/usr/share/foreman/lib/foreman/default_settings/loader.rb:45:in `block (2 levels) in load'
/usr/share/foreman/lib/foreman/default_settings/loader.rb:37:in `each'
/usr/share/foreman/lib/foreman/default_settings/loader.rb:37:in `block in load'
/usr/share/foreman/vendor/ruby/1.9.1/gems/activerecord-3.0.20/lib/active_record/connection_adapters/abstract/database_statements.rb:139:in `transaction'
/usr/share/foreman/vendor/ruby/1.9.1/gems/activerecord-3.0.20/lib/active_record/transactions.rb:207:in `transaction'
/usr/share/foreman/lib/foreman/default_settings/loader.rb:34:in `load'
/usr/share/foreman/config/initializers/foreman.rb:4:in `<top (required)>'
[...]

Accordingly, I can make this all go away, by setting opts[:value] = nil in the default_settings/loader/create method. Of course, this breaks the install "a bit".

Another thing I noticed, but can't categorize: When I recreate the database, the first rake db:migrate initializes all the tables, but it requires a second db:migrate run to start loading the settings.

Ah, finally found it! app/models/setting.rb#value= checks whether val == default before setting the value. Since at create! time the setting has no default yet (it will be only written to it a few moments later), it fails. Hard.

Now I need to figure out a way to hotfix that in my automated install until this fix is released ;-)

#3 Updated by Dominic Cleal over 6 years ago

  • Status changed from Feedback to Assigned
  • Assignee set to Dominic Cleal
  • Target version set to 1.2.0

Thanks for investigating David, I've reproduced it based on that info. This happens when you set values for settings in settings.yaml, which is meant to be supported.

#4 Updated by Dominic Cleal over 6 years ago

  • Status changed from Assigned to New
  • Assignee deleted (Dominic Cleal)

#5 Updated by Tomáš Strachota over 6 years ago

  • Assignee set to Tomáš Strachota

#6 Updated by Dominic Cleal over 6 years ago

  • Status changed from New to Ready For Testing

#7 Updated by Anonymous over 6 years ago

  • Status changed from Ready For Testing to Closed
  • % Done changed from 0 to 100

#8 Updated by Dominic Cleal about 6 years ago

  • Has duplicate Bug #3472: "instance of IO needed" failure on new install added

Also available in: Atom PDF