Project

General

Profile

Actions

Bug #2343

closed

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

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

Status:
Closed
Priority:
Normal
Category:
-
Target version:
Difficulty:
Triaged:
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 3 (0 open3 closed)

Related to Foreman - Refactor #2660: Setting model, improve tests, string parsing and change to create!ClosedTomáš Strachota06/12/2013Actions
Related to Foreman - Bug #2686: foreman-config doesn't change boolean settingsClosedDominic Cleal06/20/2013Actions
Has duplicate Foreman - Bug #3472: "instance of IO needed" failure on new installDuplicate10/22/2013Actions
Actions #1

Updated by Dominic Cleal over 11 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'

Actions #2

Updated by David Schmitt over 11 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 ;-)

Actions #3

Updated by Dominic Cleal over 11 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.

Actions #4

Updated by Dominic Cleal over 11 years ago

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

Updated by Tomáš Strachota over 11 years ago

  • Assignee set to Tomáš Strachota
Actions #6

Updated by Dominic Cleal over 11 years ago

  • Status changed from New to Ready For Testing
Actions #7

Updated by Anonymous over 11 years ago

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

Updated by Dominic Cleal about 11 years ago

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

Also available in: Atom PDF