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

YAML merge keys cannot be merged #909

Closed
jstewmon opened this issue Jul 22, 2020 · 3 comments · Fixed by #935
Closed

YAML merge keys cannot be merged #909

jstewmon opened this issue Jul 22, 2020 · 3 comments · Fixed by #935
Labels

Comments

@jstewmon
Copy link

Hi 👋 ,

I've found an issue using a YAML data source that contains anchors, aliases and merge keys. Specifically, it seems that merge keys may not be fully resolved / materialized to the anchor value once the YAML is loaded, which can cause problems working with other features.

For example, merge will not work with a mapping value which uses a merge key:

alias.yaml:

foo: &foo
  bar: baz
qux:
    <<: *foo
    qux: bar
gomplate -d alias.yaml -i '{{ merge (dict "foo" "foo") (datasource "alias").qux }}'

16:49:00 FTL  error="template: <arg>:1:40: executing \"<arg>\" at <\"alias\">: wrong type for value; expected map[string]interface {}; got map[interface {}]interface {}"

I can coerce the alias to the anchor's value by round-tripping it to get the expected result:

gomplate -d alias.yaml -i '{{ merge (dict "foo" "foo") ((datasource "alias") | toYAML | yaml ).qux }}'
map[bar:baz foo:foo qux:bar]

The issue seems specific to using merge keys. We can use an alias without issue:

foo: &foo
  bar: baz
qux: *foo
gomplate -d alias.yaml -i '{{ merge (dict "foo" "foo") ((datasource "alias") ).qux }}'
map[bar:baz foo:foo]
@hairyhenderson
Copy link
Owner

@jstewmon Hi, sorry for the late reply, and thanks for logging this! This looks to be a bug. I'll see if I can figure something out!

@hairyhenderson
Copy link
Owner

This turned out to be a bit more complicated than I expected, and I'm only just now getting back to it. This is an upstream bug in the YAML library I'm using: go-yaml/yaml#139 (comment)

Thankfully now I understand the problem and will be able to work around it 😉

@jstewmon
Copy link
Author

Woot! Thank you for digging into the issue and providing a fix! 🙏

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