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

Warning when trying to JSON-serialise undef value ("hash will be converted to string")

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Normal
    • Resolution: Fixed
    • Affects Version/s: PUP 4.10.0
    • Fix Version/s: PUP 4.10.2, PUP 5.0.0
    • Component/s: None
    • Environment:

      Puppet 4.8.3 and 4.10.0, Ubuntu 14.04, Puppetserver 2.7.2

    • Template:
    • Team:
      Puppet Developer Experience
    • Story Points:
      1
    • Sprint:
      PDE 2017-05-31
    • Release Notes:
      Bug Fix
    • Release Notes Summary:
      Hide
      A regression caused resource parameter values containing Array or Hash values with embedded {{undef}} values to report a warning "... will be converted to string" and the parameter value would end up being a String in the serialization of a Catalog.

      This is now changed so that {{undef}} values are serialized as a JSON compliant `nil` value.
      Show
      A regression caused resource parameter values containing Array or Hash values with embedded {{undef}} values to report a warning "... will be converted to string" and the parameter value would end up being a String in the serialization of a Catalog. This is now changed so that {{undef}} values are serialized as a JSON compliant `nil` value.
    • QA Risk Assessment:
      No Action

      Description

      A warning message like the following appears in Puppetserver's logs (line breaks added for readability):

      2017-04-23 16:12:15,935 WARN  [qtp2095795815-27357] [puppetserver] Puppet Resource 'Icinga2::Object::Host[dns01.prod.example.com]'
      contains a Hash value. It will be converted to the String 
      '{"distro"=>"Ubuntu", "is_virtual"=>true, "manufacturer"=>"QEMU", "os"=>"Linux", 
      "parent"=>:undef, "project"=>"dns", "fqdn"=>"dns01.prod.example.com", "service"=>"dns-cluster",
      "stage"=>"prod", "virtual"=>"kvm",
      "notification"=>{"mail"=>{"groups"=>["admins"]}, "sms"=>{"groups"=>["admins"]}}}'
      

      The resource in question looks like this:

      ...
      if getvar('::virtualisation_host') {
        $_parent = $::virtualisation_host
      } else {
        $_parent = undef
      }
      ...
      @@icinga2::object::host { $::fqdn:
        import       => $_import,
        display_name => $::fqdn,
        address      => $::fqdn,
        target       => '/etc/icinga2/objects/hosts.conf',
        tag          => $::stage,
        vars         => {
          applications => $_applications,
          distro       => $::operatingsystem,
          fqdn         => $::fqdn,
          is_virtual   => $::is_virtual,
          manufacturer => $::manufacturer,
          os           => $::kernel,
          parent       => $_parent,
          project      => $::project,
          service      => $_service,
          stage        => $::stage,
          virtual      => $::virtual,
          notification => {
            mail => {
              groups => $mail_groups,
            },
            sms  => {
              groups => $sms_groups,
            },
          },
        },
      }
      

      In this case $_parent (and therefore the parent value in the vars hash) is set to undef explicitly. This seems to trip up something in Puppet related to JSON-serialisation.

      I'll update this ticket with some reproducible code in the coming days.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned
              Reporter:
              daff Andreas Ntaflos
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Zendesk Support