-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inconsitent merge of true and false as string values and class #23
Comments
Eesh. That is a little worrying. It looks like deep_merge is treating data value |
The problem is that true and false are their own classes respectively in ruby, so these are effectively unmergeable values, deep_merge's behaviour is correct, and using deep_merge! makes the code do what would naively be expected...
|
@robb-reporo I'm not sure you're right on this - please educate me a bit more. Shouldn't "false" (string) and Shouldn't the And just a minor note - I'm the original author of this gem (not that it makes me right - just for context as to why I care about this point). |
Well, I think the default behaviour of the deep_merge function is a little unintuitive for sure, that is the default for unmergeable (eg different classes like true and false) values seems to be to retain the original... which means deep_merge doesn't overwrite in that case, but one string will overwrite another. I suspect most deep_merge! is more popular in use, I used active_support's deep merge function because at the time I was confused... |
I'm still pretty sure this is a valid bug. I looked at the tests, and for example a string should not be overwritten by an array. (cf. https://github.com/danielsdeleo/deep_merge/blob/master/test/test_deep_merge.rb#L117) I can't see why a string should be overwritten by another string if it can't be overwritten by an array? And from that, I can't see why true should overwrite false. If the lib can't merge something together, it keeps the original, unless you use the bang syntax. IIRC that was my original intent when I wrote this library. Maybe "fixing" this causes more pain than leaving it alone, I'm not sure. But my original intent was that there are a narrow set of classes that we know how to merge together (arrays directly and hashes via recursion). All other classes except That seems pretty clearly like the correct behavior to me? Should I just let this go, b/c it will break backwards compatibility? Or maybe I'm missing the point here. |
I've reopened, you are correct, and this shows true wins whichever side of the merge it is on...
|
@robmbrooks @science I opened a PR fixing the issue |
I've probably only added to the confusion but my PR (#30) proposes that boolean values should be "mergeable", so |
The deep_merge gem lacks on a issue, reported here: danielsdeleo/deep_merge#23 danielsdeleo/deep_merge#28 As yaml_extend uses this gem to merge, here is a workaround to solve this issue. It will be full forward compatible, if the original deep_merge solves its issue, due we don't patch deep_merge directly in any way.
Had the same problem, using deep_merge in my gem. So i created a workaround, by encoding booleans before merging to strings, and decoding string booleans back to real booleans. |
The text was updated successfully, but these errors were encountered: