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

Variables are mixed up #1458

Closed
ffried opened this issue Dec 5, 2022 · 2 comments
Closed

Variables are mixed up #1458

ffried opened this issue Dec 5, 2022 · 2 comments
Labels

Comments

@ffried
Copy link

ffried commented Dec 5, 2022

Describe the bug
Variables seem to be mixed up when using within a map.

Version of yq: 4.30.5
Operating system: mac
Installed via: homebrew

Input Yaml
Concise yaml document(s) (as simple as possible to show the bug, please keep it to 10 lines or less)
input.yml:

key1:
  - value1A
  - value1B
  - value1C

key2:
  - value2A
  - value2B
  - value2C

Command
The command you ran:

yq e '. as $root | keys | map(select(. == "key1" or . == "key2") | . as $kind | $root[$kind] | map({"combination": ($kind + "/" + .)})) | flatten' input.yml

Actual behavior

- combination: key1/value1A
- combination: key2/value1A
- combination: key1/value1B
- combination: key2/value1B
- combination: key1/value1C
- combination: key2/value1C
- combination: key1/value2A
- combination: key2/value2A
- combination: key1/value2B
- combination: key2/value2B
- combination: key1/value2C
- combination: key2/value2C

Expected behavior

- combination: key1/value1A
- combination: key1/value1B
- combination: key1/value1C
- combination: key2/value2A
- combination: key2/value2B
- combination: key2/value2C

Additional context

I'm aware the the expression isn't fully optimized (e.g. pick could be used). But the very same expression works in jq:

yq -o=json input.yml | jq '. as $root | keys | map(select(. == "key1" or . == "key2") | . as $kind | $root[$kind] | map({"combination": ($kind + "/" + .)})) | flatten' -

results in:

[
  {
    "combination": "key1/value1A"
  },
  {
    "combination": "key1/value1B"
  },
  {
    "combination": "key1/value1C"
  },
  {
    "combination": "key2/value2A"
  },
  {
    "combination": "key2/value2B"
  },
  {
    "combination": "key2/value2C"
  }
]

which is the equivalent to the expected yaml.

@mikefarah
Copy link
Owner

Thanks for the detailed bug description, this will be fixed in the next release along with #1566

@mikefarah
Copy link
Owner

Fixed in v4.31.2

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

No branches or pull requests

2 participants