-
Notifications
You must be signed in to change notification settings - Fork 352
Boolean properties are overriden by default values when set to false #489
Comments
This commit fixes a bug where boolean properties of the `instance’ resource were getting overriden by default values when they were set to false. Fixes lusis#489 Signed-off-by: Bogdan Katynski <[email protected]>
When
Is the issue that someone has set |
no the two return different things. the first one calls
which reads the value of the rendering setting this property to false impossible. The second line, does not call |
Wouldn't it be easier to simply override the node attribute, if you're going to use one and default to true? |
(or get rid of the node attribute) |
Ok but what's the point of letting the user set a resource property if it's getting overriden anyway and is always true? To me this is clearly a bug. |
I've just spent an hour trying to figure out why
is trying to create the account. |
Having a resource property and looking at the node object allows us to support both styles of usage (resources vs. recipes). But if someone tries to mix them, there's actually lots of ways in which this will break (separate resource collections & run contexts, chefspec, chef-shell, etc).
From what I understand, your situation is actually:
Is that more accurate? I feel like that's inconsistent. I'd almost rather raise an error there. |
no. I do not set
I'm only calling the resource. |
@bodgix can you show me a minimal example? I suspect something is setting |
Ah, I see what's happening. We should probably adjust the utility method to never return true if |
IMHO the utility method should only be called IFF the property isn't set. |
My concern is that it's a backwards-incompatible change. We should just drop support for the node object entirely if we do that 👍 (and make this a library cookbook, like it should be.) |
well but the utility method isn't called for String properties when they're set. The problem is the use of Boolean are special and this is why I propose to drop the use of
For booleans. |
the root of the problem is that an unset boolean and a boolean set to false are both falsey. and I believe that the utility function should only be called for unset properties. and it still will be with my change. |
Thank you for pointing me to the workaround. Since my patch may break backward compatibility, I decided to try it. I set ['logstash']['instance'][instance_name]['create_account'] to false in my recipe so now I have:
but the provider is still trying to create the user. I believe there is another problem and it's in the utility method this time: chef-logstash/libraries/logstash_util.rb Line 33 in d4c2749
I believe that the intention of the utility method is to return the
which evaluates to I finally managed to disable account creation by overriding
in my recipe. |
This snippet from providers/instance.rb demonstrate the issue:
when new_resource.create_account is set to false,
Logstash.get_attribute_or_default(node, @name, 'create_account')
is getting invoked because this is how the || operator works.I think that an explicit check if the property is nil should be used instead of the simplified check if it's truthy.
The text was updated successfully, but these errors were encountered: