-
-
Notifications
You must be signed in to change notification settings - Fork 234
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
Merge nil values by default #196
Merge nil values by default #196
Conversation
d2eba65
to
50d3f80
Compare
lib/config/options.rb
Outdated
@@ -127,6 +127,7 @@ def merge!(hash) | |||
current = to_hash | |||
DeepMerge.deep_merge!(hash.dup, | |||
current, | |||
merge_nil_values: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note, this is a bit controversial because it's changing behavior. If needed, this could be optional, defaulted to false (to maintain current behavior) and you can enable it via Config.merge_nil_values
similar to the overwrite_arrays option.
so, the question is:
- should this be optional
- if so, what should be the default
I can change the PR based on this feedback. Note, this is to fix #13. Whatever is decided, we can update that issue with the right way solve that issue.
Looks good, thanks! We would need few additional things before this can be merged:
@jrafanie do you think you can work on this? |
sure @pkuczynski, what do you want the default to be? If we change behavior to default to |
Make the default true. We will bump a version and publish a warning in changelog :) |
I got it @pkuczynski. I'll push those changes. |
0b2bbe1
to
73ad458
Compare
f1caeb1
to
56afa61
Compare
@@knockout_prefix = nil | ||
@@merge_nil_values = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't fix this cop offense to match the style of the existing code and thereby not change style in this feature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
CHANGELOG.md
Outdated
@@ -2,6 +2,7 @@ | |||
|
|||
## Unreleased | |||
|
|||
* **WARNING:** nil values will now overwrite an existing value. This change of behavior can be reverted via `config.merge_nil_values = false` in your Config initializer ([#196](https://github.com/railsconfig/config/pull/196)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I retained the format of the rest of the file here and didn't fix the line length cop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
56afa61
to
3ccbc79
Compare
Previously, if you merged in {a: nil}, it would not overwrite an existing value. In rubyconfig#13, this was found to be an undesirable default behavior. Now, we will merge nil values by default. You can retain the old behavior via `config.merge_nil_values = false` in your Config initializer. This required changes to deep merge, found in: danielsdeleo/deep_merge#33 This was released in deep_merge 1.2.0+. Fixes rubyconfig#13
3ccbc79
to
6d3b140
Compare
@pkuczynski Please take a look. I have added your suggestions and fixed all "reasonable" cops without changing the existing style. See my comments above. |
Looks good! Thanks for all your work on this. I will release this as 1.7.0 |
Thanks @pkuczynski 👍 |
@pkuczynski FYI, I started playing with this change more in depth in a rails app and it works! But, I did notice a minor change in behavior: we had multiple configurations sources with our "last" source coming from our monolith and defining a "ems" key that other sources would populate. Because the monolith specified the key but with no value, since those would be set by sub-sources, we were overriding the values with nil. I think that's the right behavior and we should just validate our yml so we don't accidentally squash values from other sources. |
Well, that's the risk. Your monolith should not define |
Just in case anyone else comes across this, this breaking changed tripped my up because it's not just explicit
This lead to an error The solution was to comment out (for documentation) or remove the sections that have no defined values:
|
Previously, if you merged in
{a: nil}
, it would not overwrite anexisting value. In #13, this was found to be an undesirable default
behavior.
Now, we will merge nil values by default. You can retain the old
behavior via
config.merge_nil_values = false
in your Config initializer.This required changes to deep merge, found in: danielsdeleo/deep_merge#33
This was released in deep_merge 1.2.0+.
Fixes #13