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

Inconsistent undef value received by 4.x API Ruby functions after touched by 3.x Ruby function

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Normal
    • Resolution: Done
    • Affects Version/s: PUP 5.5.3
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Template:
      PUP Bug Template
    • Method Found:
      Needs Assessment
    • CS Priority:
      Reviewed
    • QA Risk Assessment:
      Needs Assessment

      Description

      While trying to use the Stdlib function to_yaml() I believe I have discovered a bug in how Puppet handles data returned from Ruby 3.x API functions versions when passed into 4.x Ruby functions.

      It is easiest to explain with a reproducer. Give this code, where func3() and func4() are just Ruby API 3.x and 4.x functions respectively that each just return the value they were passed:

      $orig_hash = {
        'mykey'    => undef,
        'otherkey' => 'test',
      }
       
      $func4_hash = func4($orig_hash)
      notice("func4_hash: ${func4_hash}")
      notice("func4_hash_json: ${to_json($func4_hash)}")
      notice("func4_hash_yaml: ${to_yaml($func4_hash)}")
       
      $func3_hash = func3($orig_hash)
      notice("func3_hash: ${func3_hash}")
      notice("func3_hash_json: ${to_json($func3_hash)}")
      notice("func3_hash_yaml: ${to_yaml($func3_hash)}")
      

      I get this output:

      $ puppet apply --modulepath=. test/test.pp 
      Notice: Scope(Class[main]): func4_hash: {mykey => , otherkey => test}
      Notice: Scope(Class[main]): func4_hash_json: {"mykey":null,"otherkey":"test"}
      Notice: Scope(Class[main]): func4_hash_yaml: ---
      mykey: 
      otherkey: test
       
      Notice: Scope(Class[main]): func3_hash: {mykey => , otherkey => test}
      Notice: Scope(Class[main]): func3_hash_json: {"mykey":"undef","otherkey":"test"}
      Notice: Scope(Class[main]): func3_hash_yaml: ---
      mykey: :undef
      otherkey: test
       
      Notice: Compiled catalog for msp-pumtl31.msp.secure-24.net in environment production in 0.02 seconds
      Notice: Applied catalog in 0.01 seconds
      

      Note how the original data structure is correctly passed to the 4.x function with a nil value the first time, but after passing through a 3.x function the 4.x function now receives :undef and not nil.

      The expected behavior is that a 4.x Ruby function would always receive nil when passed a Puppet undef value, regardless of whether it has passed through a 3.x style function or not.

      Thank you.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned
              Reporter:
              seanmil Sean Millichamp
              Votes:
              3 Vote for this issue
              Watchers:
              7 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Zendesk Support