Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merging a dict over other types fails silently #394

Open
forquare opened this issue Feb 12, 2024 · 0 comments
Open

Merging a dict over other types fails silently #394

forquare opened this issue Feb 12, 2024 · 0 comments

Comments

@forquare
Copy link

forquare commented Feb 12, 2024

Hi 馃憢

I'm seeing this issue in a Helm Library Chart, my helm version is:

version.BuildInfo{Version:"v3.12.1", GitCommit:"f32a527a060157990e2aa86bf45010dfb3cc8b8d", GitTreeState:"clean", GoVersion:"go1.20.4"}

However, I believe the issue is likely in spring in how it uses mergo (note this issue over on mergo: Mergo not overriding destination with source).

I use mustMergeOverwrite to merge two structures of unknown contents - i.e. the values are provided once the chart is in use and I won't know the structures contents when I'm writing the library chart.

I have noticed that in most cases I get the desired result: values in the source overwrite values in the destination even if the type changes.

By "even if the type changes" I mean that if a key in the destination has a string value, but in the source it has an int value, the source gets precedence and the result of the merge is that they key now has the int value from the source.

However, this is not the case if the key in the destination is any type other than a map and the key in the source is a map. In this case the result is that the destination has precedence and the value to the key remains as specified in the source.

While this breaks things for my users on occasion, I can usually spot this and we work around the problem. While I would love the behaviour to be changed such that merging a dict over another type results in the value being a dict, a big part of the problem at the moment is that this happens silently - I would expect an error at the least.

I have an extremely basic example over at helm playground which demonstrates the issue.
Note that all "toDict" values in the dest dict retain their destination values in the output while all of the other merges happen as expected.

I'm struggling to see someone relying on this specific behaviour, and it seems like a bug to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant