Issue #16116 has been updated by Frederic Schaer.
Hi, I was hit by that one today, so I'd like to add it's even still possible to delete hash keys using ERBs. Another (bad) thing : it seems the mutability warning disappeared from the "latest" doc, whereas it's still present for 2.7. See: http://docs.puppetlabs.com/puppet/2.7/reference/lang_datatypes.html#hashes and http://docs.puppetlabs.com/puppet/latest/reference/lang_datatypes.html#hashes The following code will print a hash, delete a key in an inline template (this was my issue with 2 modules using the same source hash), and print the stripped hash : <pre> class mytest::sub::class::one { $var='cheers' $hash={ 'test1'=>{key1 => $var}, 'test2'=>{key1 => "$var"}, 'test3'=>{key1 => 'thanks'}, } } class mytest2 { include mytest::sub::class::one $hash=$mytest::sub::class::one::hash notify {'test2': message => inline_template(' 11 11 <%= @hash.inspect %> 11 ') } -> notify {'test': message => inline_template(' 22 22 <% @newlist = @hash.delete_if{|k,v| v["key1"]!="cheers"} %>hash : <%= @hash.inspect %> 22 newlist : <%= @newlist.inspect %> -- ') } } include mytest2 </pre> This results in : <pre> Notice: 11 11 {"test2"=>{"key1"=>"cheers"}, "test1"=>{"key1"=>"cheers"}, "test3"=>{"key1"=>"thanks"}} 11 Notice: 22 22 hash : {"test2"=>{"key1"=>"cheers"}, "test1"=>{"key1"=>"cheers"}} 22 newlist : {"test2"=>{"key1"=>"cheers"}, "test1"=>{"key1"=>"cheers"}} </pre> ---------------------------------------- Bug #16116: Arrays and hashes are mutable; new members can be added and existing values changed https://projects.puppetlabs.com/issues/16116#change-96065 * Author: Nick Fagerlund * Status: Accepted * Priority: Normal * Assignee: * Category: language * Target version: 3.x * Affected Puppet version: * Keywords: * Branch: ---------------------------------------- Courtesy Henrik: Puppet doesn't let you reassign variables within a given scope, but it lets you change the values of hashes and arrays by mucking with their members. That seems wrong. $myary = ['zero', 'one', 'two'] $myhash = {first => 'one', second => 'two', third => 'three'} $myary[3] = 'three' #can insert new element $myary[3] = 'something else' #can reassign notice($myary[3]) $myhash[fourth] = 'four' #can insert new element $myhash[fourth] = 'something else' #can't reassign, fails compilation notice($myhash[fourth]) $myary += ['four'] #can't append in same scope, fails compilation AND it's inconsistent, so obviously SOMETHING is whacked, even if we actually do want these objects to be mutable. I don't know what we should do about this. I think the extent to which this is being used in the wild is completely unknown. -- 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 unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/puppet-bugs. For more options, visit https://groups.google.com/groups/opt_out.
