On 2014-31-05 2:15, Robert wrote:
I've stumbled upon this very annoying bug with the future parser where
it's replacing undef with empty strings when passed inside a hash to
create_resources().

test.pp
=========
define test($var = undef) {
   notice inline_template("<%= @name %> is <% if @var %>true<% else
%>false<% end %> and of type <%= @var.class %>")
}

$config = {
   "from_create_resources" => {
     var => undef
   }
}

create_resources('test', $config)
=========

$ puppet apply ./test.pp
Notice: Scope(Test[from_create_resources]): from_create_resources is
false and of type NilClass

$ puppet apply --parser future ./test.pp
Notice: Scope(Test[from_create_resources]): from_create_resources is
true and of type String

Breaks most of my templates since I use <% if @var %> everywhere...


That is a bummer. The problem here is that the 3x API *expects* undefs to be transformed to empty string (if that is not done, other functions break). However, the 3x runtime does a poor job and only translates *some* undefs to empty strings.

We faced a dilemma: which "bug" should future parser be compliant with?
We choose the strict; translate all undefs to empty string.

In the 4x function API there is no such transformation. The intent is
to gradually move functions to the new API on a "most urgent to fix" basis.

Until this has been done, one way of solving this is to implement bridging function using the new API (if it is named the same as the 3x function, it will be chosen instead of the 3x function when using parser == future). It can then simply relay the call to the 3x implementation (without any transformation).

Tip: If attempting to do this, there may be need to transform other values such as types - this because the 3x functions does not understand the new type system, and something like File['/tmp'] results in a PResourceType in the future parser/evaluator, and needs to be transformed to a Puppet::Resource.

We are currently discussing, when and how we deal with functions
that needs to be transitioned to the 4x API. As an interim, maybe we should make the future parser bug compatible wrt. transformation of undef to empty string when these values are nested in arrays and hashes.

Sorry for the inconvenience.
Regards
- henrik

--

Visit my Blog "Puppet on the Edge"
http://puppet-on-the-edge.blogspot.se/

--
You received this message because you are subscribed to the Google Groups "Puppet 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/lmhvhh%2480m%241%40ger.gmane.org.
For more options, visit https://groups.google.com/d/optout.

Reply via email to