Jira (PUP-11438) An iterable returned by tree_each iterator does not work with reduce

31 views
Skip to first unread message

Alex Tayts (Jira)

unread,
Jan 28, 2022, 12:28:01 PM1/28/22
to puppe...@googlegroups.com
Alex Tayts created an issue
 
Puppet / Bug PUP-11438
An iterable returned by tree_each iterator does not work with reduce
Issue Type: Bug Bug
Affects Versions: PUP 7.13.1, PUP 7.12.0, PUP 7.14.0
Assignee: Unassigned
Components: Language
Created: 2022/01/28 9:27 AM
Environment:

Tested on Debian 10,11/Ubuntu 18.04,20.04/Red Hat 7,8/Oracle Linux 7,8/CentOS 7,8. Tested on the latest puppet agent versions, but likely this has been around since forever.

Priority: Major Major
Reporter: Alex Tayts

tree_each function returns an iterator, which is supposed to chain with revers_each, filter, map and reduce according to the documentation In practice one of the chained functions, reduce does not work.

The minimal code to reproduce with puppet apply:

$tree = {}
notice $tree.tree_each.reduce({}) |$m, $v| { $m } 

This results in an error:

Error: Evaluation Error: Error while evaluating a Method call, undefined method `reduce' for #<Puppet::Pops::Types::Iterable::DepthFirstTreeIterator:0x00005653899c8280>
Did you mean?  rescue (file: /srv/production/site/profile/manifests/test.pp, line: 2, column: 30) on node ruthenium-dev

joshalso 

Add Comment Add Comment
 
This message was sent by Atlassian Jira (v8.20.2#820002-sha1:829506d)
Atlassian logo

Alex Tayts (Jira)

unread,
Jan 28, 2022, 1:33:02 PM1/28/22
to puppe...@googlegroups.com
Alex Tayts updated an issue
Change By: Alex Tayts
_tree_each_ function returns an iterator, which is supposed to chain with _revers_each,_ _filter, map_ and _reduce_ according to the [documentation| [https://puppet.com/docs/puppet/7/function.html #tree-each].] In practice one of the chained functions, _reduce_ does not work.

The minimal code to reproduce with {_}puppet apply{_}:
{code:java}

$tree = {}
notice $tree.tree_each.reduce({}) |$m, $v| { $m } {code}

This results in an error:
{code:java}
Error: Evaluation Error: Error while evaluating a Method call, undefined method `reduce' for #<Puppet::Pops::Types::Iterable::DepthFirstTreeIterator:0x00005653899c8280>
Did you mean?  rescue (file: /srv/production/site/profile/manifests/test.pp, line: 2, column: 30) on node ruthenium-dev{code}
[~
joshalso josh

Alex Tayts (Jira)

unread,
Jan 28, 2022, 1:37:02 PM1/28/22
to puppe...@googlegroups.com
Alex Tayts updated an issue
_tree_each_ function returns an iterator, which is supposed to chain with _revers_each,_ _filter, map_ and _reduce_ according to the [ [ documentation| https://puppet.com/docs/puppet/7/function.html #tree-each] . |#tree-each ]   . In practice one of the chained functions, _reduce_ does not work.


The minimal code to reproduce with {_}puppet apply{_}:
{code:java}$tree = {}
notice $tree.tree_each.reduce({}) |$m, $v| { $m } {code}
This results in an error:
{code:java}Error: Evaluation Error: Error while evaluating a Method call, undefined method `reduce' for #<Puppet::Pops::Types::Iterable::DepthFirstTreeIterator:0x00005653899c8280>
Did you mean?  rescue (file: /srv/production/site/profile/manifests/test.pp, line: 2, column: 30) on node ruthenium-dev{code}
[~josh] 

Josh Cooper (Jira)

unread,
Jan 28, 2022, 1:52:01 PM1/28/22
to puppe...@googlegroups.com

Josh Cooper (Jira)

unread,
Feb 1, 2022, 4:20:03 PM2/1/22
to puppe...@googlegroups.com
Josh Cooper updated an issue
_tree_each_ function returns an iterator, which is supposed to chain with _revers_each,_ _filter, map_ and _reduce_ according to the [ [ documentation|https://puppet.com/docs/puppet/7/function.html#tree-each ] |#tree-each]. In practice one of the chained functions, _reduce_ does not work.


The minimal code to reproduce with {_}puppet apply{_}:
{code:java}$tree = {}
notice $tree.tree_each.reduce({}) |$m, $v| { $m } {code}
This results in an error:
{code:java}Error: Evaluation Error: Error while evaluating a Method call, undefined method `reduce' for #<Puppet::Pops::Types::Iterable::DepthFirstTreeIterator:0x00005653899c8280>
Did you mean?  rescue (file: /srv/production/site/profile/manifests/test.pp, line: 2, column: 30) on node ruthenium-dev{code}
[~josh] 

Josh Cooper (Jira)

unread,
Feb 1, 2022, 4:23:02 PM2/1/22
to puppe...@googlegroups.com
Josh Cooper commented on Bug PUP-11438
 
Re: An iterable returned by tree_each iterator does not work with reduce

ruthenium It seems like this has never worked. Is there another way to accomplish your use case?

Alex Tayts (Jira)

unread,
Feb 1, 2022, 7:15:01 PM2/1/22
to puppe...@googlegroups.com
Alex Tayts commented on Bug PUP-11438

Yes, there is. I have actually chatted about this with Henrik Lindberg and his workaround to coerce the tree_each output into an array before passing on to reduce works for me. Nevertheless he considered it to be a bug that should be fixed and asked me to submit it. I do agree with him because there is really no reason for this not to work.

$tree = {}
notice Array($tree.tree_each).reduce({}) |$m, $v| { $m }        # works!

If there are no plans to fix that, I think the documentation should be updated to exclude reduce from the list of the functions that could be chained to tree_each.

Nirupama Mantha (Jira)

unread,
Feb 8, 2022, 4:47:03 PM2/8/22
to puppe...@googlegroups.com

We currently don't plan to address this, you can submit a PR if you would like us to review it. We will update our documentation to remove it from our list. cc/heston.hoffman

Josh Cooper (Jira)

unread,
Feb 8, 2022, 5:09:02 PM2/8/22
to puppe...@googlegroups.com

Heston Hoffman (Jira)

unread,
Feb 8, 2022, 5:35:02 PM2/8/22
to puppe...@googlegroups.com

Heston Hoffman (Jira)

unread,
Mar 3, 2022, 2:51:03 PM3/3/22
to puppe...@googlegroups.com
Heston Hoffman assigned an issue to Unassigned

Christopher Thorn (Jira)

unread,
Mar 11, 2022, 6:47:01 PM3/11/22
to puppe...@googlegroups.com
Christopher Thorn updated an issue
Change By: Christopher Thorn
Fix Version/s: PUP 7.15.0
Fix Version/s: PUP 6.27.0

Christopher Thorn (Jira)

unread,
Mar 11, 2022, 7:01:04 PM3/11/22
to puppe...@googlegroups.com
Christopher Thorn updated an issue
Change By: Christopher Thorn
Release Notes: Not Needed
Release Notes Summary: Just a docs change to make things clear reduce isn't supported.

Josh Cooper (Jira)

unread,
Mar 31, 2022, 1:47:05 PM3/31/22
to puppe...@googlegroups.com
Josh Cooper updated an issue
Change By: Josh Cooper
Fix Version/s: PUP 7.15.0
Fix Version/s: PUP 6.27.0

Michael Hashizume (Jira)

unread,
Apr 1, 2022, 6:02:02 PM4/1/22
to puppe...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages