2->3 unlisted incompatible change to array slices?

15 views
Skip to first unread message

mpou...@afilias.info

unread,
Jun 25, 2014, 5:44:27 PM6/25/14
to puppet...@googlegroups.com

While migrating our local modules from puppet 2 to puppet 3 I think I've found a backwards-incompatible change that's not listed in the release notes.  I'd like to verify that what I'm seeing is expected, and make sure I'm not missing any other side-effects of the change.

In puppet 2 templates, array slices which returned a single element were still returned as an array, so a structure like this was valid:

    <%- myarray[-1].each do |text| -%>
    <%=text%>
    <%- end -%>

In puppet 3 templates this throws an error:
undefined method `each' for "foo":String at ...

It looks like slices that return only a single element are now returned as the type of the array element rather than as an array.  I don't see this change mentioned anywhere at <http://docs.puppetlabs.com/puppet/3/reference/release_notes.html>.

Is there anything else to this change that I'm missing, or are there other side-effects to this I should be watching out for?


jcbollinger

unread,
Jun 26, 2014, 9:18:58 AM6/26/14
to puppet...@googlegroups.com


Yes.
  1. The meaning of Ruby scriptlet code in an ERB template is determined by Ruby, not by Puppet.  If there had been a change, then there would be no particular reason to expect it to be called out in Puppet's release notes.
  2. The Ruby expression myarray[-1] does not compute an array slice, it returns the last element of the array.  As far as I am aware, it hasn't computed a slice in any version of Ruby.  The behavior you describe is normal, and does not itself reflect a change in Puppet or Ruby.
Presumably the real code that caused you trouble has something more subtle going on.  For example, maybe the structure of myarray ends up being different in Puppet 3 than in Puppet 2. I would need to see the real manifests by which its value is assigned to guess at why.


John


Reply all
Reply to author
Forward
0 new messages