Jira (PUP-11663) max/min core functions are incorrect for Semver types

20 views
Skip to first unread message

Sean Millichamp (Jira)

unread,
Oct 25, 2022, 2:40:01 PM10/25/22
to puppe...@googlegroups.com
Sean Millichamp created an issue
 
Puppet / Improvement PUP-11663
max/min core functions are incorrect for Semver types
Issue Type: Improvement Improvement
Affects Versions: PUP 7.20.0
Assignee: Henrik Lindberg
Components: Functions
Created: 2022/10/25 11:39 AM
Priority: Normal Normal
Reporter: Sean Millichamp

The Puppet max/min functions do not handle Semver types correctly. The "Any" data type function signature matches, they are converted to strings, compare as strings, and are often incorrect. Based on the spec tests for max/min it looks to be explicitly called out behavior, which I assume it means that it can't change until a new major Puppet version: https://github.com/puppetlabs/puppet/blob/main/spec/unit/functions/max_spec.rb#L77

It would be great if min/max would support all the applicable data types in their native/correct fashion. At least Semver, Timestamp, and Timespan should all be added and the deprecated Any behavior removed.

Add Comment Add Comment
 
This message was sent by Atlassian Jira (v8.20.11#820011-sha1:0629dd8)
Atlassian logo

Morgan Rhodes (Jira)

unread,
Oct 25, 2022, 4:05:03 PM10/25/22
to puppe...@googlegroups.com
Morgan Rhodes assigned an issue to Unassigned
Change By: Morgan Rhodes
Assignee: Henrik Lindberg

Morgan Rhodes (Jira)

unread,
Oct 25, 2022, 4:10:03 PM10/25/22
to puppe...@googlegroups.com

Morgan Rhodes (Jira)

unread,
Oct 25, 2022, 4:10:03 PM10/25/22
to puppe...@googlegroups.com

Ben Ford (Jira)

unread,
Oct 25, 2022, 5:03:14 PM10/25/22
to puppe...@googlegroups.com
Ben Ford commented on Improvement PUP-11663
 
Re: max/min core functions are incorrect for Semver types

Sean Millichamp this doesn't fix the issue, but I've got a simple module that makes versioncmp() easier to use. A PR to add Semver support would be rad.

https://github.com/binford2k/binford2k-version

Josh Cooper (Jira)

unread,
Mar 9, 2023, 12:56:02 PM3/9/23
to puppe...@googlegroups.com
Josh Cooper updated an issue
 
Change By: Josh Cooper
Sprint: Phoenix 2023-03-29

Josh Cooper (Jira)

unread,
Mar 9, 2023, 12:56:03 PM3/9/23
to puppe...@googlegroups.com
Josh Cooper updated an issue
The Puppet max/min functions do not handle Semver types correctly. The "Any" data type function signature matches, they are converted to strings, compare as strings, and are often incorrect. Based on the spec tests for max/min it looks to be explicitly called out behavior, which I assume it means that it can't change until a new major Puppet version: https://github.com/puppetlabs/puppet/blob/main/spec/unit/functions/max_spec.rb#L77

It would be great if min/max would support all the applicable data types in their native/correct fashion. At least Semver, Timestamp, and Timespan should all be added and the deprecated Any behavior removed.


Current behavior:

{noformat}
$ bundle exec puppet apply -e 'notice(max(Semver.new("2.0.0"), Semver.new("10.0.0")))'
Warning: The max() function's auto conversion of Any to String is deprecated - change to convert input before calling, or use lambda
   (file & line not available)
Notice: Scope(Class[main]): 2.0.0
{noformat}

Desired behavior:

{noformat}
$ bundle exec puppet apply -e 'notice(max(Semver.new("2.0.0"), Semver.new("10.0.0")))'
Notice: Scope(Class[main]): 10.0.0
{noformat}

Similarly for the {{min}} function and when comparing {{Timestamp}} and {{Timespan}}

Josh Cooper (Jira)

unread,
Mar 9, 2023, 1:55:02 PM3/9/23
to puppe...@googlegroups.com

Josh Cooper (Jira)

unread,
Mar 15, 2023, 1:31:02 AM3/15/23
to puppe...@googlegroups.com
Josh Cooper updated an issue
The Puppet max/min functions do not handle Semver types correctly. The "Any" data type function signature matches, they are converted to strings, compare as strings, and are often incorrect. Based on the spec tests for max/min it looks to be explicitly called out behavior, which I assume it means that it can't change until a new major Puppet version: https://github.com/puppetlabs/puppet/blob/main/spec/unit/functions/max_spec.rb#L77

It would be great if min/max would support all the applicable data types in their native/correct fashion. At least Semver, Timestamp, and Timespan should all be added and the deprecated Any behavior removed.

Current behavior:

{noformat}
$ bundle exec puppet apply -e 'notice(max(Semver.new("2.0.0"), Semver.new("10.0.0")))'
Warning: The max() function's auto conversion of Any to String is deprecated - change to convert input before calling, or use lambda
   (file & line not available)
Notice: Scope(Class[main]): 2.0.0
{noformat}

Desired behavior:

{noformat}
$ bundle exec puppet apply -e 'notice(max(Semver.new("2.0.0"), Semver.new("10.0.0")))'
Notice: Scope(Class[main]): 10.0.0
{noformat}

Similarly for the {{min}} function and when comparing {{Timestamp}} and {{Timespan}} . Note {{Semver}}, {{Timestamp}} and {{Timespan}} are already comparable so the following returns 1 because the

{noformat}
$ bundle exec puppet apply -e "notice(compare(Semver.new('10.0.0'), SemVer('2.0.0')))"

Notice: Scope(Class[main]): 1
{noformat}

Josh Cooper (Jira)

unread,
Mar 15, 2023, 1:33:02 AM3/15/23
to puppe...@googlegroups.com
Josh Cooper updated an issue
The Puppet max/min functions do not handle Semver types correctly. The "Any" data type function signature matches, they are converted to strings, compare as strings, and are often incorrect. Based on the spec tests for max/min it looks to be explicitly called out behavior, which I assume it means that it can't change until a new major Puppet version: https://github.com/puppetlabs/puppet/blob/main/spec/unit/functions/max_spec.rb#L77

It would be great if min/max would support all the applicable data types in their native/correct fashion. At least Semver, Timestamp, and Timespan should all be added and the deprecated Any behavior removed.

Current behavior:

{noformat}
$ bundle exec puppet apply -e 'notice(max(Semver.new("2.0.0"), Semver.new("10.0.0")))'
Warning: The max() function's auto conversion of Any to String is deprecated - change to convert input before calling, or use lambda
   (file & line not available)
Notice: Scope(Class[main]): 2.0.0
{noformat}

Desired behavior:

{noformat}
$ bundle exec puppet apply -e 'notice(max(Semver.new("2.0.0"), Semver.new("10.0.0")))'
Notice: Scope(Class[main]): 10.0.0
{noformat}

Similarly for the {{min}} function and when comparing {{Timestamp}} and {{Timespan}}.


Note {{Semver}}, {{Timestamp}} and {{Timespan}} are can already comparable so be compared using the {{compare}} function, for example, the following " returns - 1 because , 0 or 1 if first value is smaller, equal or larger than the
second value." So this change will mean {{min}} and {{max}} behave consistently with {{compare}}:

{noformat}
$ bundle exec puppet apply -e "notice(compare(Semver.new('10.0.0'), SemVer('2.0.0')))"
Notice: Scope(Class[main]): 1
{noformat}

Michael Hashizume (Jira)

unread,
Mar 22, 2023, 12:42:02 PM3/22/23
to puppe...@googlegroups.com

Michael Hashizume (Jira)

unread,
Apr 12, 2023, 4:34:02 PM4/12/23
to puppe...@googlegroups.com
Michael Hashizume updated an issue
Change By: Michael Hashizume
Release Notes: Enhancement
Release Notes Summary: The max and min functions now recognize SemVer, Timespan, and Timestamp types properly.

Aria Li (Jira)

unread,
Apr 18, 2023, 5:52:02 PM4/18/23
to puppe...@googlegroups.com
Aria Li updated an issue
Change By: Aria Li
Fix Version/s: PUP 8.0.0
Reply all
Reply to author
Forward
0 new messages