Jira (PUP-11717) Can't "dig" into facts when legacy facts are excluded

23 views
Skip to first unread message

Josh Cooper (Jira)

unread,
Jan 17, 2023, 12:37:03 AM1/17/23
to puppe...@googlegroups.com
Josh Cooper created an issue
 
Puppet / Task PUP-11717
Can't "dig" into facts when legacy facts are excluded
Issue Type: Task Task
Assignee: Unassigned
Created: 2023/01/16 9:36 PM
Fix Versions: 7.22.0
Priority: Normal Normal
Reporter: Josh Cooper

If legacy facts are disabled, then the $facts variable will refer to an instance of Facter::FactCollection, which subclasses Hash, rather than a Hash instance. See FACT-3179.

When attempting to dig into facts, e.g. $facts.dig('..'), then the dig function will fail, because the function expects a Collection not a Runtime:

$ puppet apply -e '$facts.dig("ruby")' --no-include_legacy_facts
Error: Evaluation Error: Error while evaluating a Method call, 'dig' parameter 'data' expects a value of type Undef or Collection, got Runtime (line: 1, column: 11) on node localhost

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

Josh Cooper (Jira)

unread,
Jan 17, 2023, 12:39:02 AM1/17/23
to puppe...@googlegroups.com

Josh Cooper (Jira)

unread,
Jan 17, 2023, 8:20:02 PM1/17/23
to puppe...@googlegroups.com

Morgan Rhodes (Jira)

unread,
Jan 18, 2023, 1:26:03 PM1/18/23
to puppe...@googlegroups.com
Morgan Rhodes updated an issue
Change By: Morgan Rhodes
Sprint: Phoenix 2023-02-01

Josh Cooper (Jira)

unread,
Jan 18, 2023, 2:15:02 PM1/18/23
to puppe...@googlegroups.com

Josh Cooper (Jira)

unread,
Jan 18, 2023, 6:51:03 PM1/18/23
to puppe...@googlegroups.com

Ben Ford (Jira)

unread,
Jan 18, 2023, 7:43:02 PM1/18/23
to puppe...@googlegroups.com
Ben Ford commented on Task PUP-11717
 
Re: Can't "dig" into facts when legacy facts are excluded

The PR looks like it also protects fact() from breaking, but maybe worth a quick check.

Josh Cooper (Jira)

unread,
Jan 18, 2023, 7:54:03 PM1/18/23
to puppe...@googlegroups.com
Josh Cooper commented on Task PUP-11717

Looks like it's ok:

❯ bx puppet --version
7.21.0
❯ bx puppet apply -e 'notice(fact("ruby.version"))' --no-include_legacy_facts
Notice: Scope(Class[main]): 2.7.6
Notice: Compiled catalog for localhost in environment production in 0.01 seconds
Notice: Applied catalog in 0.04 seconds

The dig function is a little unique in that it requires a Collection parameter, so it triggers the issue. I'm not sure how many user function do that level of type checking, but I'm sure someone is.

Josh Cooper (Jira)

unread,
Jan 19, 2023, 1:41:03 PM1/19/23
to puppe...@googlegroups.com
Josh Cooper updated an issue
Change By: Josh Cooper
If legacy facts are disabled (PUP-11662) , then the {{$facts}} variable will refer to an instance of {{ {} Facter::FactCollection { }} } , which subclasses {{ {} Hash { }} } , rather than a {{Hash}} instance. See FACT-3179.

When attempting to dig into facts, e.g. {{
{} $facts.dig('..') { }} } , then the dig function will fail, because the [function expects a {{Collection}}|https://github.com/puppetlabs/puppet/blob/7f96b47f8419ad95509552f75690fad957fb97a9/lib/puppet/functions/dig.rb#L32] not a {{ {} Runtime { }} } :

{noformat}
$ puppet apply -e '$facts.dig("ruby")' --no-include_legacy_facts
Error: Evaluation Error: Error while evaluating a Method call, 'dig' parameter 'data' expects a value of type Undef or Collection, got Runtime (line: 1, column: 11) on node localhost
{noformat}

Josh Cooper (Jira)

unread,
Jan 24, 2023, 8:30:01 PM1/24/23
to puppe...@googlegroups.com
Josh Cooper updated an issue
Change By: Josh Cooper
Release Notes: Bug Fix
Release Notes Summary: Catalog compilation no longer fails when using the "dig" function and excluding legacy facts.

Josh Cooper (Jira)

unread,
Jan 24, 2023, 8:30:03 PM1/24/23
to puppe...@googlegroups.com
Josh Cooper updated an issue
Change By: Josh Cooper
Fix Version/s: PUP 7.23.0

Parker Leach (Jira)

unread,
Feb 1, 2023, 11:39:02 AM2/1/23
to puppe...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages