FYI - .to_hash bug


#1

Hey guys,

I just wanted to let people know I recently filed CHEF-4596.

It’s a common thing in chef to call .to_hash on an attribute so you can loop
on it (iterating on attributes will usually give you not the thing you want
because of the way Chef autovivifies)…

Turns out in Chef 10… at least some versions… .to_hash will sometimes
de-dupe internal arrays of a hash. So if you have {:foo=>[‘a’, ‘b’, ‘a’]} in
your hash somewhere, what you’ll get is {:foo=>[‘a’, ‘b’]} and this could
seriously mess some people up in very subtle ways.


Phil Dibowitz phil@ipom.com
Open Source software and tech docs Insanity Palace of Metallica
http://www.phildev.net/ http://www.ipom.com/

“Be who you are and say what you feel, because those who mind don’t matter
and those who matter don’t mind.”

  • Dr. Seuss

#2

Hey Phil,

Looks like you might be seeing something similar to
https://tickets.opscode.com/browse/CHEF-1804

-M

On Fri, Oct 4, 2013 at 2:33 PM, Phil Dibowitz phil@ipom.com wrote:

Hey guys,

I just wanted to let people know I recently filed CHEF-4596.

It’s a common thing in chef to call .to_hash on an attribute so you can
loop
on it (iterating on attributes will usually give you not the thing you want
because of the way Chef autovivifies)…

Turns out in Chef 10… at least some versions… .to_hash will sometimes
de-dupe internal arrays of a hash. So if you have {:foo=>[‘a’, ‘b’, ‘a’]}
in
your hash somewhere, what you’ll get is {:foo=>[‘a’, ‘b’]} and this could
seriously mess some people up in very subtle ways.


Phil Dibowitz phil@ipom.com
Open Source software and tech docs Insanity Palace of Metallica
http://www.phildev.net/ http://www.ipom.com/

“Be who you are and say what you feel, because those who mind don’t matter
and those who matter don’t mind.”

  • Dr. Seuss

#3

On 10/04/2013 11:35 AM, Mike wrote:

Hey Phil,

Looks like you might be seeing something similar
to https://tickets.opscode.com/browse/CHEF-1804

No, I believe that’s just because those examples iterate directly on
Attributes which is not allowed. If they called ‘.to_hash’ first, they’d be fine.

Which has a bug. :slight_smile:

Steven Danna’s got a fix that seems to work for us, but… if someone was
relying on the ‘.uniq’ behavior of .to_hash, it’d be an unpleasant surprise,
so there’s some discussion going on.


Phil Dibowitz phil@ipom.com
Open Source software and tech docs Insanity Palace of Metallica
http://www.phildev.net/ http://www.ipom.com/

“Be who you are and say what you feel, because those who mind don’t matter
and those who matter don’t mind.”

  • Dr. Seuss