Bug #8707

Scope.lookupvar() returns undef perhaps should return nil

Added by Karl Pietri 10 months ago. Updated about 1 month ago.

Status:Accepted Start date:07/29/2011
Priority:Normal Due date:
Assignee:- % Done:

0%

Category:templates
Target version:2.7.x
Affected Puppet version:2.7.10 Branch:
Keywords:
Votes: 2

Description

When in a erb template in puppet if you use scope.lookupvar() with a variable that doesn’t exist you get a return value of the label undefined (:undefined) this breaks being able to do this:

<% if scope.lookupvar("::ipadress_eth2") %>i have an eth2 <% end %>

Examples:

    err(inline_template('testing truth: <% if scope.lookupvar("::ipaddress_eth1") %>has ip: <%= scope.lookupvar("::ipaddress_eth1") %><% else %>has no ip<% end %>'))
    err(inline_template('testing undefined str: <% if scope.lookupvar("::ipaddress_eth1")!="undefined" %>has ip: <%= scope.lookupvar("::ipaddress_eth1") %><% else %>has no ip<% end %>'))
    err(inline_template('testing undefined label: <% if scope.lookupvar("::ipaddress_eth1")!=:undefined %>has ip: <%= scope.lookupvar("::ipaddress_eth1") %><% else %>has no ip<% end %>'))

output:

Jul 29 12:10:29 monitor1.example.com puppet-master[533]: (Scope(Class[Shared::Sshd])) testing truth: has ip: undefined
Jul 29 12:10:29 monitor1.example.com puppet-master[533]: (Scope(Class[Shared::Sshd])) testing undefined str: has ip: undefined
Jul 29 12:10:29 monitor1.example.com puppet-master[533]: (Scope(Class[Shared::Sshd])) testing undefined label: has no ip

Perhaps the function should return nil instead of :undefined to prevent confusion

-karl

PS not sure if this is a bug or a feature request


Related issues

related to Puppet - Bug #12948: undefined method `join' for :undef:Symbol Closed 03/04/2012

History

Updated by James Turnbull 10 months ago

  • Status changed from Unreviewed to Needs Decision
  • Assignee set to Nigel Kersten

Seems reasonable to me and I have a funny feeling this might have been fixed recently?

Updated by James Turnbull 10 months ago

  • Category set to templates

Updated by Nigel Kersten 10 months ago

  • Status changed from Needs Decision to Accepted
  • Assignee deleted (Nigel Kersten)
  • Target version set to 2.7.x

Updated by Steve Shipway about 1 month ago

  • Affected Puppet version changed from 2.7.1 to 2.7.10

Please fix this; I’ve lost just over an hour trying to work out why lookupvar(“foo”).to_i is returning 55758 (turns out this is the value of :undefined). We have 2.7.10 and the problem is still present.

Updated by Andrew Parker about 1 month ago

The lookupvar() method in the master branch for Telly currently does return nil instead of :undefined, should this be backported to 2.7?

Updated by Ken Barber about 1 month ago

I’d be wary because users may have already put in work-arounds in their content.

This behaviour change is probably better done in a release jump like 2.8 as people would be more likely to read release notes and test their content properly. On Apr 20, 2012 5:08 PM, tickets@puppetlabs.com wrote:

Issue #8707 has been updated by Andrew Parker.

The lookupvar() method in the master branch for Telly currently does

return nil instead of :undefined, should this be backported to 2.7?

Bug #8707: Scope.lookupvar() returns undef perhaps should return nilhttps://projects.puppetlabs.com/issues/8707#change-61053

  • Author: Karl Pietri
  • Status: Accepted
  • Priority: Normal
  • Assignee:
  • Category: templates
  • Target version: 2.7.x
  • Affected Puppet version: 2.7.10
  • Keywords:
  • Branch:

When in a erb template in puppet if you use scope.lookupvar() with a variable that doesn’t exist you get a return value of the label undefined (:undefined) this breaks being able to do this:

<% if scope.lookupvar(“::ipadress_eth2”) %>i have an eth2 <% end %>

Examples:

err(inline_template('testing truth: <% if scope.lookupvar("::ipaddress_eth1") %>has ip: <%= scope.lookupvar("::ipaddress_eth1") %><% else %>has no ip<% end %>'))
err(inline_template('testing undefined str: <% if scope.lookupvar("::ipaddress_eth1")!="undefined" %>has ip: <%= scope.lookupvar("::ipaddress_eth1") %><% else %>has no ip<% end %>'))
err(inline_template('testing undefined label: <% if scope.lookupvar("::ipaddress_eth1")!=:undefined %>has ip: <%= scope.lookupvar("::ipaddress_eth1") %><% else %>has no ip<% end %>'))

output:

Jul 29 12:10:29 monitor1.example.com puppet-master[533]: (Scope(Class[Shared::Sshd])) testing truth: has ip: undefined Jul 29 12:10:29 monitor1.example.com puppet-master[533]: (Scope(Class[Shared::Sshd])) testing undefined str: has ip: undefined Jul 29 12:10:29 monitor1.example.com puppet-master[533]: (Scope(Class[Shared::Sshd])) testing undefined label: has no ip

Perhaps the function should return nil instead of :undefined to prevent confusion

-karl

PS not sure if this is a bug or a feature request

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

Also available in: Atom PDF