yaml-import icon indicating copy to clipboard operation
yaml-import copied to clipboard

Merge with property being null results in previous objects being lost

Open henhal opened this issue 6 years ago • 0 comments

When merging multiple items, properties being null will overwrite any existing objects from previously imported files.

Example:

sub1.yml:

foo:
  name: foo
  age: 42
bar:
  name: bar
sub2.yml:

foo:

bar:
  age: 25
parent.yml:

!!import/merge
- sub1.yml
- sub2.yml

This results in foo becoming null in the merged output:

foo: null
bar:
  name: bar
  age: 25

If making foo an empty object instead of null, i.e., foo: {} in sub2.yml, the properties of foo and bar are both merged properly. In YAML, it's an easy mistake to forget to add {} to objects that happen to be empty.

It would be nice if merging {name: foo, age:42} with null would behave the same as when merging with an empty object {}. Is the current behaviour of having null overwrite previous objects intentional?

In other words, I'd like the merged output of the above example to become:

The desired output would be:

foo:
  name: foo
  age: 42
bar:
  name: bar
  age: 25

henhal avatar Sep 27 '19 10:09 henhal