Skip to content

Commit

Permalink
Merge pull request #1296 from fluent/fix-bug-not-to-overwrite-default…
Browse files Browse the repository at this point in the history
…-value-with-nil

Fix a bug not to overwrite default value with nil
  • Loading branch information
tagomoris authored Oct 27, 2016
2 parents 8d3e779 + c76477a commit 566038a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
4 changes: 1 addition & 3 deletions lib/fluent/configurable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ def configure(conf)
root.instance_eval{ @params.keys }.each do |param_name|
next if param_name.to_s.start_with?('@')
varname = "@#{param_name}".to_sym
if (! root[param_name].nil?) || (instance_variable_defined?(varname) && instance_variable_get(varname).nil?)
instance_variable_set(varname, root[param_name])
end
instance_variable_set(varname, root[param_name])
end

self
Expand Down
12 changes: 6 additions & 6 deletions lib/fluent/plugin/out_exec_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,20 @@ def initialize
def configure(conf)
if tag_key = conf['tag_key']
# TODO obsoleted?
@in_tag_key = tag_key
@out_tag_key = tag_key
conf['in_tag_key'] = tag_key
conf['out_tag_key'] = tag_key
end

if time_key = conf['time_key']
# TODO obsoleted?
@in_time_key = time_key
@out_time_key = time_key
conf['in_time_key'] = time_key
conf['out_time_key'] = time_key
end

if time_format = conf['time_format']
# TODO obsoleted?
@in_time_format = time_format
@out_time_format = time_format
conf['in_time_format'] = time_format
conf['out_time_format'] = time_format
end

super
Expand Down
16 changes: 16 additions & 0 deletions test/config/test_configurable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,12 @@ class SubOwner < Owner
end
end

class NilOwner < Owner
config_section :buffer do
config_set_default :size_of_something, nil
end
end

class FlatChild
include Fluent::Configurable
attr_accessor :owner
Expand Down Expand Up @@ -1078,6 +1084,16 @@ class TestConfigurable < ::Test::Unit::TestCase
assert_equal 2048, child.size_of_something
end

test 'default values can be overwritten with nil' do
owner = ConfigurableSpec::OverwriteDefaults::NilOwner.new
child = ConfigurableSpec::OverwriteDefaults::BufferChild.new
assert_equal :buffer, child.class.merged_configure_proxy.configured_in_section

child.owner = owner
child.configure(config_element('ROOT', '', {}, []))
assert_nil child.size_of_something
end

test 'the first configured_in (in the order from base class) will be applied' do
child = ConfigurableSpec::OverwriteDefaults::BufferSubclass.new
assert_equal :buffer, child.class.merged_configure_proxy.configured_in_section
Expand Down

0 comments on commit 566038a

Please sign in to comment.