Uploaded image for project: 'Puppet'
  1. Puppet
  2. PUP-5925

Optional data type and data binding with undef as default value

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Normal
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: PUP 4.4.0
    • Component/s: Docs
    • Labels:
      None
    • Environment:

      Ubuntu Trusty with puppet-agent 1.3.5

    • Template:
    • Epic Link:
    • Story Points:
      1
    • Sprint:
      Language 2016-02-24
    • Release Notes:
      Bug Fix
    • Release Notes Summary:
      Hide
      A small but annoying problem in data binding has been fixed, where if you defined a data key for a parameter to be nil (i.e. undef) and did not have a default expression for the parameter that also specified undef (or some other value) an error would be raised. Now, if nil/undef is bound as value in data, and there is no default expression, the value undef is assigned to the parameter instead of giving an error).
      Show
      A small but annoying problem in data binding has been fixed, where if you defined a data key for a parameter to be nil (i.e. undef) and did not have a default expression for the parameter that also specified undef (or some other value) an error would be raised. Now, if nil/undef is bound as value in data, and there is no default expression, the value undef is assigned to the parameter instead of giving an error).

      Description

      ORIGINAL REPORT


      All the files are in .zip attached file. I have a (very basic) module with the function data.pp as data provider and the default value of a parameter is undef:

      function test::data {
        {
          test::foo::param => undef,
        }
      }
      

      In the class ::test::foo, I have this code:

      class test::foo ( Optional[ String[1] ] $param ) { }
      

      As you can see, the type of the parameter $param is an Optional which means that a undef value is accepted. However, if I test this code:

      include '::test::foo'
      

      I have an error:

      ~# puppet apply /puppet/modules/test/examples/example.pp 
      Error: Evaluation Error: Error while evaluating a Function Call, Class[Test::Foo]: expects a value for parameter 'param' at /puppet/modules/test/examples/example.pp:1:1 on node puppet.athome.priv
      

      It seems to me that it's not the expected behavior.
      Regards.

      PS: currently a possible and simple workaround is to set a undef default value in the declaration of the class like this:

      class test::foo ( Optional[ String[1] ] $param = undef ) { }
      

      but you have to set the undef value in two different places.

      UPDATE


      This is fixed so that if an undef value is bound for a parameter key data binding will assign that undef to the parameter if the parameter does not have a default value expression. Earlier such a binding would have failed and required that the parameter had a default value expression of = undef in order to make a lookup of undef possible.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              flaf Francois Lafont
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Zendesk Support