Jira (PUP-10321) Resource 'notify': Attribute 'message' accepts Array but only use the first element

8 views
Skip to first unread message

Frédéric Lespez

unread,
Feb 29, 2020, 4:13:03 AM2/29/20
to puppe...@googlegroups.com
Frédéric Lespez created an issue
 
Puppet / Bug PUP-10321
Resource 'notify': Attribute 'message' accepts Array but only use the first element
Issue Type: Bug Bug
Assignee: Unassigned
Created: 2020/02/29 1:12 AM
Priority: Normal Normal
Reporter: Frédéric Lespez

Puppet Version: 6.13.0
Puppet Server Version: 6.9.0
OS Name/Version: Debian 10 (Buster)

Consider the following code:

 

class test_notify {
  $a = ['a', 'b', 'c']
  $b = {'a' => 1, 'b' => 2,  'c' => 3 }
  notify {
    'Array':
      message => $a,
    ;
    'Hash':
      message => $b,
    ;
  }
}

 

Desired Behavior:

I was expecting this:

Notice: ["a", "b", "c"]
Notice: /Stage[main]/Test_notify/Notify[Array]/message: defined 'message' as ['a', 'b', 'c']
Notice: {"a"=>1, "b"=>2, "c"=>3}
Notice: /Stage[main]/Test_notify/Notify[Hash]/message: defined 'message' as {
  'a' => 1,
  'b' => 2,
  'c' => 3
} 

That is to say I was expecting that the 'message' attribute to behave in the same way for Array and Hash values.

Actual Behavior:

But instead, 'notify' resource only displays the first element of the array, silently ignoring all the others:

Notice: a
Notice: /Stage[main]/Test_notify/Notify[Array]/message: defined 'message' as 'a'
Notice: {"a"=>1, "b"=>2, "c"=>3}
Notice: /Stage[main]/Test_notify/Notify[Hash]/message: defined 'message' as {
  'a' => 1,
  'b' => 2,
  'c' => 3
}

With a Hash value, the 'notify' resource displays all the Hash.

 

 

Add Comment Add Comment
 
This message was sent by Atlassian Jira (v8.5.2#805002-sha1:a66f935)
Atlassian logo

Henrik Lindberg (Jira)

unread,
Feb 29, 2020, 6:54:04 AM2/29/20
to puppe...@googlegroups.com
Henrik Lindberg commented on Bug PUP-10321
 
Re: Resource 'notify': Attribute 'message' accepts Array but only use the first element

That indeed looks like a bug. OTOH - allowing notify to do the string conversion means you have no control over how the resulting string is formatted. It is recommended to turn values into a string before assigning it to the message attribute.

Depending on how much control you want - use one of:

  • "${theArray}"
  • $theArray.join(" ,")
  • String($theArray) - with lots of options

Frédéric Lespez

unread,
Mar 3, 2020, 12:12:03 PM3/3/20
to puppe...@googlegroups.com

I will open a ticket to update the docs.

For the record, I discovered this when I was debugging a manifest. I lost a lot of time figuring out it was notify that was mangling the data.

At the beginning, I wasn't even expecting the 'message' attributes to accept hashes, but it does and it handles them 'logically'. So in the end, I assumed it was also the case for arrays... My bad.

Allowing notify to do the string conversion may not be the solution but doing nothing is endorsing weird behavior.

Why not changing the 'message' attributes so that it only accepts strings ?

At least, notify behavior will be coherent with predicable results.

 

Frédéric Lespez

unread,
Mar 3, 2020, 1:31:03 PM3/3/20
to puppe...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages