Closed afiune closed 9 years ago
This is okay, but it seems like this is only needed if you're requiring the same file twice, which shouldn't be happening.
We are just writing some tests .. :smile:
@danielsdeleo what if we instance_exec
or class_exec
that file again? Or used that class to class_exec
something else? Could that possibly be re-defining that constant?
@afiune you could also add
if defined?(NOT_PASSED)
require pry; binding.pry
NOT_PASSED = Object.new
end
And inspect when/how it is getting re-defined. I would be curious to know how its getting redefined if you have a repro.
The problem: if you declared a chef_role in 12.5, it would fail when trying to access the ChefRole.name.
The affecting Chef 12 change: This happened because the "name" property in 12.5 uses a new NOT_PASSED
constant to determine whether the user passed a value or not. In other words, if you call name "hi"
then value == "hi", if you call name
with no arguments, value == NOT_PASSED
.
The cause: Chef::Resource::Role
defines its own NOT_PASSED
, and the Ruby lookup meant that the base class (where name
is defined) was sometimes picking up Chef::Resource::Role::NOT_PASSED
and sometimes picking up Chef::NOT_PASSED
. This meant comparisons would sometimes fail and weird things would happen.
To fix it, we:
Chef
class using class Chef; class Resource; class Role < Chef::Resource::LWRPBase
instead of class Chef::Resource::Role < Chef::Resource::LWRPBase
. This gave us access to the Chef::NOT_PASSED
constant.You need to not be using flat indenting, sooner or later someone like me will come along and do something significant enough that I want the autoformatting in my editor to work correctly and I'll remove all the flat indenting.
I would love to fix that ... It's up to John and Tyler to give the green light! 😁
On Wednesday, September 2, 2015, Lamont Granquist notifications@github.com wrote:
You need to not be using flat indenting, sooner or later someone like me will come along and do something significant enough that I want the autoformatting in my editor to work correctly and I'll remove all the flat indenting.
— Reply to this email directly or view it on GitHub https://github.com/chef/cheffish/pull/70#issuecomment-137243541.
Salim Afiune — Solutions Engineer
917.716.0448 – afiune@chef.io – my: Linkedin http://www.linkedin.com/in/afiune Twitter http://www.twitter.com/afiune
CHEF
CHEF.IO <http://www.chef.io/>
TM
chef.io http://www.chef.io/ Blog http://www.chef.io/blog/ Facebook https://www.facebook.com/getchefdotcom Twitter https://twitter.com/chef Youtube https://www.youtube.com/getchef
@lamont-granquist Fair enough, but it seems reasonable to have it as a separate change, so it doesn't obscure everything else that's going on by marking every line of a file as changed.
:+1:
adding ?w=0
to the url will remove the whitespace from the diffs
Oh that is true Lamont!!
I'll indent them before merge.
I'm :+1: on the code changes, though, it is the correct way to do all of this. Opening up classes with the colon notation tends to end badly...
hold on .. we are working on the indentation!
:+1:
almost done.. please hold :smile:
Done! :awyeah:
:+1:
There are two changes like NOT_PASSED = Object.new unless defined?(NOT_PASSED)
still in there, I'd hope we don't need that now?
@danielsdeleo we still need that for 12.4 compatibility. 12.5 is when NOT_PASSED was introduced.
@danielsdeleo https://github.com/chef/cheffish/pull/70#issuecomment-137201782 has the full explanation.
Alright this is getting super exciting!!!
Ruby lookup meant that the base class (where name is defined) was sometimes picking up Chef::Resource::Role::NOT_PASSED and sometimes picking up Chef::NOT_PASSED
What are the different circumstances? I would think that you'd look things up in the lexical scope of the method definition, which got fixed here by doing class A; class B
instead of class A::B
@danielsdeleo the issue was that the base class Chef::Resource
(whose lexical scope and inheritance hierarchy has not changed) was picking up Chef::Resource::Role::NOT_PASSED
when you called name
with no arguments (since name is a property, it uses the NOT_PASSED
thingy in a method that looks like def name(value=NOT_PASSED)
). However, the code that actually compared it to NOT_PASSED
(in params_validate, I think) picked up Chef::NOT_PASSED
.
Ugh, yeah. Seems like we should either do the comparison in the class that defines that constant or just re-use the same one. I might actually advocate for back porting Chef::NOT_PASSED
by opening up class Chef
and adding NOT_PASSED = Object.new unless defined?(NOT_PASSED)
since you need the compatibility.
Yeah, I'd be cool with that too.
This commit modified the way we create the
Resources
andProviders
insideCheffish
.Instead of creating them as:
We now use:
The same for the Providers.
The main reason for this is to open Chef class and consume what is in there. In this case the
NOT_PASSED
constant! We also check that theNOT_PASSED
constant is not defined before declaring it.This was failing on
chefdk
with chef versionchef-12.5.0
Here the snippet of the error: