Explode operator incorrectly references old values #1482
Closed
Description
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(.) ' -