The Puppet Labs Issue Tracker has Moved: https://tickets.puppetlabs.com

This issue tracker is now in read-only archive mode and automatic ticket export has been disabled. Redmine users will need to create a new JIRA account to file tickets using https://tickets.puppetlabs.com. See the following page for information on filing tickets with JIRA:

Bug #21508

Can't access a lambda variable in a template (Future Parser)

Added by Kit Plummer almost 3 years ago. Updated over 2 years ago.

Status:ClosedStart date:
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:-
Target version:3.3.0
Affected Puppet version:3.2.2 Branch:https://github.com/puppetlabs/puppet/pull/1735
Keywords:future parser scope template variable

We've Moved!

Ticket tracking is now hosted in JIRA: https://tickets.puppetlabs.com


Description

https://gist.github.com/kitplummer/5877926

Doesn’t work: <% @value %> Does work: <%= scope.lookupvar('value') %>

History

#1 Updated by eric sorenson almost 3 years ago

  • Status changed from Unreviewed to Investigating
  • Assignee set to Henrik Lindberg

Henrik — I confirmed this but I’m not sure whether it’s intentional or not. The docs say:

When a lambda is evaluated, this takes place in a local scope that shadows outer scopes. Each invocation of a lambda sets up a fresh local scope. The variables assigned (and the lambda parameters) are immutable once assigned, and they can not be referenced from code outside of the lambda block. The lambda block may however use variables visible in the scope where the lambda is given, as in this example...

But in this case, the template access is inside the lambda block.

I have a minimalistic reproduction case here: Gist 5881061

#2 Updated by eric sorenson almost 3 years ago

  • Description updated (diff)

#3 Updated by Henrik Lindberg almost 3 years ago

  • Status changed from Investigating to In Topic Branch Pending Review
  • Keywords changed from future parser to future parser scope template variable
  • Branch set to https://github.com/puppetlabs/puppet/pull/1735

The cause was that Scope#to_hash did not include the local variables. That function was used by the TemplateWrapper to configure the available instance variables. Ergo – they were missing.

The fix includes the local variables, but skips all match (ephemeral) variables $0-$n just like the original implementation did. (i.e. it is backwards compatible).

#4 Updated by Anonymous almost 3 years ago

  • Status changed from In Topic Branch Pending Review to Merged - Pending Release
  • Assignee deleted (Henrik Lindberg)

Merged into master in 0a824.

#5 Updated by Anonymous over 2 years ago

  • Target version set to 3.3.0

#6 Updated by Anonymous over 2 years ago

  • Status changed from Merged - Pending Release to Closed

Released in 3.3.0

#7 Updated by Anonymous over 2 years ago

Released in 3.3.0

Also available in: Atom PDF