Project

General

Profile

Actions

Bug #11415

closed

ENC fails with undefined method `value' for #<LookupKey ..>

Added by Dominic Cleal over 8 years ago. Updated almost 6 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
External Nodes
Target version:
Difficulty:
Triaged:
Fixed in Releases:
Found in Releases:

Description

2015-08-19T09:54:34 [app] [W] Failed to generate external nodes for test.example.com
 | NoMethodError: undefined method `value' for #<LookupKey:0x000000089759c0>
 | /home/dcleal/.rvm/gems/ruby-2.0.0-p353@foreman/gems/activemodel-3.2.21/lib/active_model/attribute_methods.rb:407:in `method_missing'
 | /home/dcleal/.rvm/gems/ruby-2.0.0-p353@foreman/gems/activerecord-3.2.21/lib/active_record/attribute_methods.rb:149:in `method_missing'
 | /home/dcleal/code/foreman/foreman/app/services/foreman/parameters/caster.rb:13:in `initialize'
 | /home/dcleal/code/foreman/foreman/app/services/classification/base.rb:152:in `new'
 | /home/dcleal/code/foreman/foreman/app/services/classification/base.rb:152:in `type_cast'
 | /home/dcleal/code/foreman/foreman/app/services/classification/base.rb:84:in `value_of_key'
 | /home/dcleal/code/foreman/foreman/app/services/classification/class_param.rb:12:in `block (2 levels) in enc'
 | /home/dcleal/code/foreman/foreman/app/services/classification/class_param.rb:11:in `each'
 | /home/dcleal/code/foreman/foreman/app/services/classification/class_param.rb:11:in `block in enc'
 | /home/dcleal/.rvm/gems/ruby-2.0.0-p353@foreman/gems/activerecord-3.2.21/lib/active_record/relation/delegation.rb:6:in `each'
 | /home/dcleal/.rvm/gems/ruby-2.0.0-p353@foreman/gems/activerecord-3.2.21/lib/active_record/relation/delegation.rb:6:in `each'
 | /home/dcleal/code/foreman/foreman/app/services/classification/class_param.rb:8:in `enc'
 | /home/dcleal/code/foreman/foreman/app/models/host/managed.rb:875:in `lookup_keys_class_params'
 | /home/dcleal/code/foreman/foreman/app/models/host/managed.rb:385:in `info'
From: /home/dcleal/code/foreman/foreman/app/services/classification/base.rb @ line 152 Classification::Base#type_cast:

    151: def type_cast(key, value)
 => 152:   binding.pry if value.nil?
    153:   Foreman::Parameters::Caster.new(key, :attribute_name => :value, :to => key.key_type, :value => value).cast
    154: rescue TypeError
    155:   Rails.logger.warn "Unable to type cast #{value} to #{key.key_type}" 
    156: end

> key
=> #<LookupKey id: 58, key: "dnsdomain", created_at: "2013-02-21 11:45:29", updated_at: "2013-02-21 11:45:29", puppetclass_id: nil, default_value: nil, path: nil, description: nil, validator_type: nil, validator_rule: nil, is_param: true, key_type: nil, override: true, required: true, lookup_values_count: 0, merge_overrides: nil, avoid_duplicates: nil, use_puppet_default: nil>
> value
=> nil

Seems that the key in this case is overridden, but the default vale is nil. The value is passed into Foreman::Parameters::Caster, which because it's nil assumes that it needs to try and call key.value to retrieve it. Perhaps using has_key? is better to check even if a nil value was passed in, or don't use reflection.


Related issues 1 (0 open1 closed)

Related to Foreman - Refactor #10232: move validations and casting out of lookup keys and values into single-responsibility classesClosedTom Caspy04/22/2015Actions
Actions #1

Updated by Dominic Cleal over 8 years ago

  • Related to Refactor #10232: move validations and casting out of lookup keys and values into single-responsibility classes added
Actions #2

Updated by Tom Caspy over 8 years ago

  • Assignee set to Tom Caspy
Actions #3

Updated by The Foreman Bot over 8 years ago

  • Status changed from New to Ready For Testing
  • Pull request https://github.com/theforeman/foreman/pull/2676 added
  • Pull request deleted ()
Actions #4

Updated by Tom Caspy over 8 years ago

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

Also available in: Atom PDF