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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bool issue #249

Open
mybigman opened this issue Dec 7, 2023 · 2 comments
Open

bool issue #249

mybigman opened this issue Dec 7, 2023 · 2 comments

Comments

@mybigman
Copy link

mybigman commented Dec 7, 2023

type Foo struct {
	A string
	B int64
	C bool
	D string
}

src := Foo{
	A: "a",
	B: 52,
	C: false,
	D: "2012-02-02",
}

dest := Foo{
	A: "b",
	B: 12,
	C: true,
	D: "2012-02-03",
}

mergo.Merge(&dest, src, mergo.WithOverride)
fmt.Println(src)
fmt.Println(dest)
fmt.Printf("%+v", dest)

got

{a 52 false 2012-02-02}
{a 52 true 2012-02-02}
{A:a B:52 C:true D:2012-02-02}

expected

{a 52 false 2012-02-02}
{a 52 false 2012-02-02}
{A:a B:52 C:false D:2012-02-02}
type Foo struct {
	A string
	B int64
	C bool
	D string
}

src := Foo{
	A: "a",
	B: 52,
	C: true,
	D: "2012-02-02",
}

dest := Foo{
	A: "b",
	B: 12,
	C: false,
	D: "2012-02-03",
}

mergo.Merge(&dest, src, mergo.WithOverride)
fmt.Println(src)
fmt.Println(dest)
fmt.Printf("%+v", dest)

got

{a 52 true 2012-02-02}
{a 52 true 2012-02-02}
{A:a B:52 C:true D:2012-02-02}

expected

{a 52 true 2012-02-02}
{a 52 true 2012-02-02}
{A:a B:52 C:true D:2012-02-02}

As you can see overriding true with false fails, however overriding false with true works

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar
@esperoz
Copy link

esperoz commented Jan 30, 2024

Stuck with the same issue. Fixed with mergo.WithoutDereference and pointer to bool in structure

@w570955342
Copy link

You can try using mergo.WithOverwriteWithEmptyValue instead of mergo.WithOverride.

Kidswiss added a commit to vshn/appcat that referenced this issue Mar 5, 2024
By default mergo doesn't allow merging a non empty value with an
empty value. For example if a field is a string "hello" it would not
override it, if the to be merged object contains the same field with "".

This works well until someone wants to override a true boolean with a
false boolean, in which case the merge doesn't happen.

By setting `mergo.WithOverwriteWithEmptyValue`, we can force mergo to
merge empty values into noni empty values.

darccio/mergo#249
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

3 participants