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

Explode operator incorrectly references old values #1482

Closed
FooRider opened this issue Dec 17, 2022 · 2 comments
Closed

Explode operator incorrectly references old values #1482

FooRider opened this issue Dec 17, 2022 · 2 comments
Labels

Comments

@FooRider
Copy link

When an object using merge alias is copied, the anchor value is modified and explode operator is used, the copied object contains old unmodified data.

Version of yq: 4.28.1 (windows) 4.30.6 (linux)
Operating system: linux and windows
Installed via: choco on windows, snap on linux

Input Yaml
data1.yml:

a: &a
  x: "OriginalValue"
b:
  <<: *a

Command
The command you ran:

yq ' .c = .b | .a.x = "ModifiedValue" | explode(.) ' input.yml

Actual behavior

a:
  x: "ModifiedValue"
b:
  x: "ModifiedValue"
c:
  x: "OriginalValue"

Expected behavior

a:
  x: "ModifiedValue"
b:
  x: "ModifiedValue"
c:
  x: "ModifiedValue"

Additional context
I believe result from expected behavior should be correct, since if the explode operator is omitted, the resulting yaml is:

a: &a
  x: "ModifiedValue"
b:
  !!merge <<: *a
c:
  !!merge <<: *a

which is correctly exploded to the yaml in expected behavior.

Furthermore, correct result can be achieved by splitting the script into two calls of yq by runing:

yq ' .c = .b | .a.x = "ModifiedValue" ' input.yml | yq ' explode(.) ' -
@mikefarah
Copy link
Owner

Thanks for the detailed bug description - will release the fix in the next release

@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