Jira (PUP-11446) Facts returning nil are converted to empty string

17 views
Skip to first unread message

Sean Millichamp (Jira)

unread,
Feb 2, 2022, 3:16:02 PM2/2/22
to puppe...@googlegroups.com
Sean Millichamp created an issue
 
Puppet / Bug PUP-11446
Facts returning nil are converted to empty string
Issue Type: Bug Bug
Assignee: Unassigned
Created: 2022/02/02 12:15 PM
Priority: Normal Normal
Reporter: Sean Millichamp

In sanitize_facts null fact results are not preserved. With the modern data type support Puppet can and should properly preserve null values returned in fact data OR, at least, remove the fact from the data entirely so a reference to it, as an undefined key, returns undef.

I understand that this would likely need to be done on a major version change, but I just wasted hours trying to figure out why my undef-expecting code was not behaving as intended.

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

Josh Cooper (Jira)

unread,
Feb 7, 2022, 11:48:02 PM2/7/22
to puppe...@googlegroups.com
Josh Cooper commented on Bug PUP-11446
 
Re: Facts returning nil are converted to empty string

Our intention is for Facter 4 to handle null fact value the same as was done in 3 (and 2 to a lesser extent). I believe null fact values are ignored, so facter will continue searching for another resolution and use that.

We've talked about being able to use the puppet type system to write facts. Then you could specify a type like Binary, Sensitive, Undef, etc but that work was never prioritized, see PUP-478.

Also you should be able to run facter with --debug to see what each fact resolves to for example:

[2022-02-07 20:46:17.110406 ] DEBUG Facter::Util::Fact - value for myfact is still nil 

I would expect that to work for all types of facts (custom vs external), but I don't know if that's true?

Sean Millichamp (Jira)

unread,
Feb 8, 2022, 6:43:02 AM2/8/22
to puppe...@googlegroups.com

josh To be clear, what I observed and reported doesn't seem to be a facter issue. In fact, interestingly, facter by itself seem to have the inverse behavior as to what I saw versus when the facts are presented in Puppet.

Given two Ruby facts, one simple fact which returns "nil" and one which returns a hash containing a single key with a nil value you get these results with the facter CLI:

  1. facter --version
    3.14.17 (commit ce1f2bb4a91a1ac4ae5852091c96ae6ee3712e23)
  2. facter -p --json mysimplefact mystructuredfact
    {
    "mysimplefact": "",
    "mystructuredfact": { "mykey": null }

    }

Facter does the correct thing with the structured fact, but turns the simple fact nil value into a string.

Now, those same Facts as presented by Puppet:

Notice: mystructuredfact:

{"mykey":""}

Notice: mysimplefact: null
Notice: mysimplefact is key in facts hash: false

The value of the structured fact key is now the empty string, the simple fact value is now null, and on top of that the fact doesn't even get added to the $facts hash.

The behavior I think we should have is that the data types returned by Facter should be preserved when used in Puppet. I think that a fact which returns nil as its only value should continue to not be present in the facts hash. At the very least, the behavior should be consistent between Puppet and Facter.

You can see the quick module I put together for the above testing here: https://github.com/seanmil/facttest

As an aside to this issue, Puppet type system support in facts would be awesome!

Josh Cooper (Jira)

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

Josh Cooper (Jira)

unread,
Mar 28, 2022, 4:30:02 PM3/28/22
to puppe...@googlegroups.com
Josh Cooper updated an issue
Change By: Josh Cooper
Sprint: Phoenix 2022-04-13

Josh Cooper (Jira)

unread,
Mar 30, 2022, 11:37:04 AM3/30/22
to puppe...@googlegroups.com

Lisa Ross (Jira)

unread,
Mar 30, 2022, 11:45:03 AM3/30/22
to puppe...@googlegroups.com
Lisa Ross updated an issue
Change By: Lisa Ross
Sprint: Phoenix 2022-04-13

Nirupama Mantha (Jira)

unread,
Mar 30, 2022, 11:51:04 AM3/30/22
to puppe...@googlegroups.com
Nirupama Mantha updated an issue
Change By: Nirupama Mantha
Sprint: Phoenix 2022-04-13

Josh Cooper (Jira)

unread,
Mar 30, 2022, 12:47:01 PM3/30/22
to puppe...@googlegroups.com
Josh Cooper commented on Bug PUP-11446
 
Re: Facts returning nil are converted to empty string

I confirmed that Facter 3 and 4 behave inconsistently with respect to fact values that return nil. I'll file that as a separate FACT ticket. This ticket partially masks that issue because when using Facter 4, puppet converts nil fact values to an empty string. So from a puppetserver/puppet code perspective, the fact values that resolve to nil are always converted to empty string, regardless of which facter implementation is used.

Some history on fact values:

In Puppet 3, puppet used to stringify facts, so all fact values were stringified, including nil to "".

This was made configurable in Puppet 4.x, see https://github.com/puppetlabs/puppet/commit/3a19fff52c15266a3171b9bcf93bc1db1788c3b8, so that it was possible to preserve String, Integer, Array, Hash, etc. However, the "sanitize" method doesn't have an explicit case for NilClass so we continued to stringify nil to "".

In Puppet 4, we removed the stringify facts option (see https://github.com/puppetlabs/puppet/commit/e1c8724df80190946ebde0559eb15fb4902797cc), so that "basic" types like boolean, integer, string, etc were preserved, but nil is still converted to ""

Reply all
Reply to author
Forward
0 new messages