Skip to content

Inplace updating a sequence with an anchor unsets the anchor #1269

Closed
@ashwin1dd

Description

@ashwin1dd

Describe the bug
Appending to a sequence inplace unsets its anchor.
It shouldn't affect the anchor at all, and should've only affected the sequence.

Version of yq: 4.25.3
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)
data1.yml:

 a: &hello
   - x
   - y
 b: *hello

Command
The command you ran:

yq -i '.a += ["z"]' data1.yml

Actual behavior

a:
  - x
  - y
  - z
b: *hello

Expected behavior

a: &hello
  - x
  - y
  - z
b: *hello

Additional context
Add any other context about the problem here.

Activity

mikefarah

mikefarah commented on Jul 13, 2022

@mikefarah
Owner

Yep that's a bug - will fix in the next release.

As a workaround, you can do the following:

yq '.a = .a + "z"' file.yaml
mikefarah

mikefarah commented on Jul 13, 2022

@mikefarah
Owner

Sorry github autoclosed - will close when the fix is actually released..

mikefarah

mikefarah commented on Jul 15, 2022

@mikefarah
Owner

Fixed in v4.26.1

added a commit that references this issue on Oct 29, 2024
f393cf3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @mikefarah@ashwin1dd

        Issue actions

          Inplace updating a sequence with an anchor unsets the anchor · Issue #1269 · mikefarah/yq