WARN: <attribute> nil currently does not overwrite the value of <attribute>


#1

I am getting this message a lot lately and wonder what the expected fix is.

https://travis-ci.org/michaelklishin/cassandra-chef-cookbook/builds/85223100


#2

It means you have code that is calling mirrorlist nil or mirrorlist(nil), which for backwards compat is currently a no-op (or more specifically it is equivalent to mirrorlist() as a getter. This warning was added because some people expected to be able to set things explicitly to nil. If you didn’t intend to explicitly set to nil, you should remove the line setting it like that.


#3

The kind of code that often hits this problem looks something like this:

action :something do
  file "/whatever" do
    owner new_resource.owner
  end
end

(…as an aside discourse just won the internet for me because it renders markdown…)

What happens there current is that if you do not specify an owner on the new_resource it is nil and then you wind up with file being passed owner nil which doesn’t set the owner to nil, but is a no-op because it magically gets turned into an accessor. What you need to write instead is:

action :something do
  file "/whatever" do
    owner new_resource.owner unless new_resource.owner.nil?
  end
end

Or something that rhymes with that. So that when new_resource.owner is nil on your resource that you are writing, you do not attempt to set the owner on the file sub-resource you are using.

And this isn’t such a big deal when considering the owner property on the file resource since nil is both a legitimate value and the default. It is more of a problem when considering some of the properties on the deploy_revision resource which have default values that are hashes. If you use the deploy_revision resource as a sub-resource and don’t guard passing your properties into its properties then you are relying on the fact that nil in Chef-12 means “the default hash” while in Chef-13 we will be changing this so that nil means nil. This will change behavior in the case when users don’t specify that property on your resource which is most likely the common case, which is most likely the case you really don’t want to have break. Hence, the loud deprecation warning. There’s most likely other nasty sharp edge cases as well which will go away eventually when properties are nillable in Chef-13.