Issue #15813 has been reported by Josh Cooper.
----------------------------------------
Bug #15813: Deprecate and eliminate magic parameter array handling
https://projects.puppetlabs.com/issues/15813
Author: Josh Cooper
Status: Accepted
Priority: Normal
Assignee:
Category: language
Target version:
Affected Puppet version: 0.23.0
Keywords: parameter property array munge validate
Branch:
Puppet's parser will automatically de-arrayify single element arrays for
parameters (and properties). See `lib/puppet/parser/resource.rb`
<pre>
result[p] = if v.is_a?(Array) and v.length == 1
v[0]
else
v
end
</pre>
As a result when writing a custom type, the parameter's validate and munge
methods may receive an array or string depending on what values were specified
in the manifest. This leads to idioms such as:
<pre>
munge do |value|
# I don't really know how this is happening.
value = value.shift if value.is_a?(Array)
</pre>
and
<pre>
munge do |value|
value = [value] unless value.is_a?(Array)
</pre>
However, the magic only happens when parsing a manifest, not when writing tests
that create resources. For example:
<pre>
$ puppet apply -e "exec { '/bin/true': environment => [ 'foo=bar']}"
values = [values] unless values.is_a? Array
(rdb:1) values
"foo=bar"
</pre>
But:
<pre>
$ irb
>> require 'puppet'
>> Puppet::Type.type(:exec).new(:command => '/bin/true', :environment =>
>> ['foo=bar'])
values = [values] unless values.is_a? Array
(rdb:1) values
["foo=bar"]
</pre>
If a parameter only accepts a single argument, then the DSL should support this
easily, e.g. `newparam(:timeout, :array => false)`
See also #6746 and
<https://github.com/puppetlabs/puppet/commit/46252b5bb858a1f2b87cc8646f3a59f935c58061>
--
You have received this notification because you have either subscribed to it,
or are involved in it.
To change your notification preferences, please click here:
http://projects.puppetlabs.com/my/account
--
You received this message because you are subscribed to the Google Groups
"Puppet Bugs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/puppet-bugs?hl=en.