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

sort_formats does not sort consistently with MRI Ruby which causes issues when find .find processes the hash to select a choice

    XMLWordPrintable

Details

    • Bug
    • Status: Accepted
    • Normal
    • Resolution: Unresolved
    • None
    • None
    • None
    • None
    • Hide

      spec test passes

      Show
      spec test passes
    • Coremunity
    • Automated Test
    • Needs Assessment

    Description

      get_format relies on the order that .find processes the hash to find the first entry to use. So the order of the hash which is insertion order matters.

      There is a problem with Puppet::Pops::Type::StringConverter.sort_formats its passed an array which it sorts based on assignablity and rank order. This method on Ruby is not consistent in the order of the hash it ends up creating.

      I had it process 3 entries from in the array, in the normal order and reverse order and then printed out the values:

         sort_formats(merged[-6..-4])
         sort_formats(merged[-6..-4].reverse) 
      

      The array's after sorting look like this. These arrays should be sorted in the same order:

      format_map:
      key: Hash rank: 2
      key: Array rank: 4
      key: Binary rank: 0
       
      format_map:
      key: Binary rank: 0
      key: Hash rank: 2
      key: Array rank: 4
      

      I think there are a couple issues with this part of the code:

              else
                # arbitrary order if disjunct (based on name of type)
                rank_a = type_rank(a)
                rank_b = type_rank(b)
                if rank_a == 0 || rank_b == 0
                  a.to_s <=> b.to_s
                else
                  rank_a <=> rank_b
                end
      

      Why do we ignore the rank if any one of the key's has a rank of 0?

      Do we want a sort of this instead? where we use the rank if one of them is set and reverse the rank comparison so that high ranked items are higher?
      Or should we be only using the a.to_s <=> b.to_s check when the ranks match

                if rank_a == 0 && rank_b == 0
                  a.to_s <=> b.to_s
                else
                  rank_b <=> rank_a
                end
      

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              eric.delaney Eric Delaney
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:

                Zendesk Support