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

Merge breaks when merging a node with a sequence. #36

Open
ArcticSnowman opened this issue Aug 6, 2020 · 7 comments
Open

Merge breaks when merging a node with a sequence. #36

ArcticSnowman opened this issue Aug 6, 2020 · 7 comments

Comments

@ArcticSnowman
Copy link

ArcticSnowman commented Aug 6, 2020

Given a node that is a sequence

node1: &node1
  - item1
  - item2
  - item3

node2:
  <<: [ *node1 ]

I get the following error:

Expected hash for merge key at centos7/v5.18.2/lib/perl5/YAML/PP/Constructor.pm line 160, <STDIN> line 1.
 at centos7/v5.18.2/lib/perl5/YAML/PP/Loader.pm line 92.
node1: &node1
  item1: {}
  item2: {}
  item3: {}

node2:
  <<: [ *node1 ]

Works for node that are hashes.

@perlpunk
Copy link
Owner

perlpunk commented Aug 6, 2020

That's expected behaviour. Merge keys only work for hashes.

@ArcticSnowman
Copy link
Author

https://yaml.org/type/merge.html

 If the value associated with the merge key is a sequence, then this sequence is expected to contain mapping nodes and each of these nodes is merged in turn according to its order in the sequence.

So an array of scalars can't be merge? That would be nice if it was possible.

@perlpunk
Copy link
Owner

perlpunk commented Aug 6, 2020

<<: [ *node1 ]

here the "value associated with the merge key" is already a sequence. But the actual nodes in that sequence have to be mappings.
Merging sequences is not possible with this feature.

There are ideas how to make that possible in the next YAML version.
But also I might add a custom tag to YAML::PP that allows merging sequences.

@ArcticSnowman
Copy link
Author

Ah, that sequence..

@ArcticSnowman
Copy link
Author

See https://metacpan.org/pod/YAML::LoadBundle for ideas..

@perlpunk
Copy link
Owner

perlpunk commented Aug 6, 2020

I was rather thinking about using tags. The merge key for mappings is also basically a tag, it's just implicit.
Explicit it would be: !!merge <<: ...

Something like:

seq1: &s1 [a, b, c]
seq2: &s2 [d, e, f]
merged: !merge-seq [*s1, *s2]

Since YAML has tags, there's no need to use special named scalars and structures.

Edit: but yeah, options like deep merge for hashes and so on would also be nice.

@ArcticSnowman
Copy link
Author

Yeah I believe our LoadBundle pre-dates the merge feature in YAML. Might suggest to the authors of the LoadBundle to consider adding support for a "TAG" based approach as well as a custom key based approach.

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

2 participants