Issue #15380 has been updated by eric sorenson.

Status changed from Unreviewed to Accepted
Assignee set to Chris Price

Yep, that seems surprising (in a bad way). Transferring back to you since you 
did the hard work of figuring out what is going on.
----------------------------------------
Bug #15380: Confusing side effects occur during Puppet::Resource#to_hash
https://projects.puppetlabs.com/issues/15380#change-68927

Author: Chris Price
Status: Accepted
Priority: Normal
Assignee: Chris Price
Category: 
Target version: 
Affected Puppet version: 
Keywords: 
Branch: 


There is a method in Puppet::Resource called "parse_title", which, as far as I 
can tell, is only ever called via Puppet::Resource#to_hash.  The #parse_title 
method appears to be the only place in the code where we interact with 
"#title_patterns", an optional method that types can specify in order to allow 
namevar munging (and potentially also to help support composite namevars?).

This caused some confusion for us in puppetdb ticket #15321 .  In that ticket 
we observed a behavior where a File (directory) resource was being referenced 
in some places in the catalog using a trailing slash, and in other places *not* 
using a trailing slash.  The reason that puppet is able to resolve both Strings 
to match the correct File resource is because the #title_patterns defined for 
the File resource provide some regex magic that will munge the trailing slash 
off of a File resource's 'title' param before setting the value of the 'path' 
namevar.  Then, elsewhere (catalog.rb, ~ line 85), puppet creates an aliased 
reference to the resource for both Strings (if the title and the munged namevar 
do not match exactly).

It's not impossible to work around this, but it's entirely unintuitive that if 
a caller attempts to look up the namevar directly using Puppet::Resource#[], 
they may get a different result than if they attempt to look it up using 
Puppet::Resource#to_hash()#[].  This title_pattern munging should perhaps 
happen during the initialize method of the Resource object, or lazily during 
calls to the #[] method.  It seems wrong for it to only happen as a side effect 
of calling "#to_hash"; which I would presume that most callers would expect to 
be a simple data structure transformation rather than having any actual effects 
on the data itself.


-- 
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.

Reply via email to