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

Inconsistent hash order with Ruby 1.8

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Normal
    • Resolution: Won't Fix
    • None
    • None
    • Compiler
    • None
    • Ruby 1.8.7

    Description

      Hash table ordering in Puppet 3.x with Ruby 1.8 is inconsistent. It is known that Ruby 1.8 does not guarantee that hash tables are ordered by insertion order, like 1.9 does. However, whatever ordering Ruby 1.8 uses for a given hash table, it stays consistent, and is always the same whenever you iterate through it.

      This is not true in Puppet 3.x used with Ruby 1.8, while it used to work with no problems in 2.7.x. The following code reproduces the issue:

      $h = {
        'foo' => 1,
        'bar' => 2,
        'baz' => 3,
      }
      $t = inline_template("
        <%- for k, v in scope.lookupvar('h') -%>
        <%= \"#{k} => #{v}\" %>
        <%- end -%>
      ")
      warning($t)
      

      On different runs of the code above, the ordering will be different. This makes it impossible to use hash iteration in a template, because the resulting file will keep being changed due to ordering.

      Attachments

        Activity

          People

            andy Andrew Parker
            andrenth Andre Nathan
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Zendesk Support