Skip to content

Explode operator incorrectly references old values #1482

Closed
@FooRider

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(.) ' -

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions