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 function does not overwrite if new value is falsy #134
Comments
I found the same. This breaks the idea and "contract" implemented here: https://github.com/Masterminds/sprig/blob/master/dict.go#L80 I whipped up an example that shows the unexpected behaviour: package main
import (
"fmt"
"github.com/imdario/mergo"
)
func main() {
map1 := map[string]interface{}{
"deep": map[string]interface{}{
"enabled": true,
},
"key": "default",
}
map2 := map[string]interface{}{
"deep": map[string]interface{}{
"enabled": false,
},
"key": "overwritten",
}
mergo.Merge(&map1, map2)
fmt.Println(map1)
} Expected output
Actual output$ go get -u github.com/imdario/mergo
map[deep:map[enabled:true] key:default] Cross referenced from darccio/mergo#91 |
It seems like the correct function invocation should be:
Then it overwrites/merges those values correctly. |
Looks like this had been resolved/can be closed @jcheroske ? |
Yes, with the addition of mergeOverwrite this is solved. Now even available
in helm. Have fun deep merging to you all :)
…On Fri 15. Mar 2019 at 01:34, Dean Coakley ***@***.***> wrote:
Looks like this had been resolved/can be closed @Overbryd
<https://github.com/Overbryd> ?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#134 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABSdzHLE6_bwO0MFnsWvOw5nQ_mnMsSks5vWuqhgaJpZM4ZkKev>
.
|
With |
The issue is still happening on latest HELM3:
Both
|
It seems that order of args should be reversed for mergeOverwrite:
Produces:
|
Given the following code:
The output is as expected:
But if the second dict's key is falsy, the value is not overwritten:
Results in:
Any falsy value will be skipped:
This is not the behavior of Javascript's Object.assign:
Sprig's behavior feels extremely counter-intuitive. When I'm merging dicts, if a key has a value assigned, that's the value I care about. It's language-specific falsyness feels irrelevant in this context.
The text was updated successfully, but these errors were encountered: