future parser changes undef to string inside create_resources (tested on puppet 3.5.1 and puppet 3.6.1)

288 views
Skip to first unread message

Robert

unread,
May 30, 2014, 8:15:36 PM5/30/14
to puppet...@googlegroups.com
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...

Henrik Lindberg

unread,
Jun 2, 2014, 9:52:13 AM6/2/14
to puppet...@googlegroups.com
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/

Kevin Häfeli

unread,
Jul 31, 2014, 9:34:49 AM7/31/14
to puppet...@googlegroups.com
After some debugging, I finally found this post. 
Thank you for posting this issue, that saved me probably a lot of time :-)

I had this problem with jfryman's nginx module, when I tried to create some vhosts with or without the parameter "auth_basic". 
Atm I've some auth_basic => undef resulting in a broken nginx vhost file, because the nginx module getting an empty string and putting it into the vhost config.
Instead of an undef and doing nothing :-)

Anyway: "fixed" it with a condition like the following and looking forward to 4.x ;)
if $auth_basic == undef { create_resources $vhost_hash } else { create_resources $vhost_hash_without_auth_basic }
Reply all
Reply to author
Forward
0 new messages