Yq: --explodeAnchors / -X doesn't explode keys (work in 3.3.1 and 3.3.2)

Created on 15 Jun 2020  路  8Comments  路  Source: mikefarah/yq

Describe the bug

-X / --explodeAnchors doesn't work now in 3.3.2 or 3.3.1 (for the read command at least).
The last version when it worked was 3.3.0.

This should work:

1.yaml

errors:
  - &ts_sync_loss ts_sync_loss
properties:
  *ts_sync_loss: int

but outputs:

errors:
  - ts_sync_loss
properties:
  *ts_sync_loss: int

i.e. ts_sync_loss is not dereferenced .

Command

$ <1.yml yq r -X -

Version 3.3.0 does work right.

bug

Most helpful comment

Ok I originally misunderstood the yaml file - now I see that the aliases are for the map keys! I didn't realise you could do that in yaml, neat.

Sorry it took me a while. This should be fixable.

All 8 comments

please follow the bug template - there is not enough information in this for me to replicate

@mikefarah Mike, I updated the issue. Try it now please.

That's not how you use anchors and aliases, I can't quite work out what you are trying to do, but it needs to be something like:

errors:
  - &ts_sync_loss ts_sync_loss # this creates a variable for the value 'ts_sync_loss'
properties: *ts_sync_loss # this references that variable

@mikefarah I don't think you're right.

You can try out my example with any of the available validators/parsers:
https://yaml-online-parser.appspot.com/
https://codebeautify.org/yaml-validator
http://www.yamllint.com/
鈥攊t works just fine, so I believe it's definitely a bug.

Sorry, but we are you keeping this closed @mikefarah?

Just to clarify things.

It transpired that the original YAML was actullay INCORRECT.

Specifically, this:

errors:
  - &ts_sync_loss ts_sync_loss
properties:
  *ts_sync_loss: int

should read as:

errors:
  - &ts_sync_loss ts_sync_loss
properties:
  *ts_sync_loss : int

(note the extra space after *ts_sync_loss).
Thus the reference PyYaml parser was actually wrong by allowing for space-less colons after anchors (but works well with the correct syntax).

Unfortunately for this tool it doesn't make any difference, it still fails.

Consider this YAML:

devs:
  - &dev1  Alice
  - &dev2  Bob
  - &devop Jane
time:
  - name: Project 1
    devs:
      *dev1 : 120 hours
      *devop : 32 hours 
  - name: Project 2
    devs:
      *dev2 : 154 hours
      *devop : 21 hours 

It works with these popular YAML parsers:

Ok I originally misunderstood the yaml file - now I see that the aliases are for the map keys! I didn't realise you could do that in yaml, neat.

Sorry it took me a while. This should be fixable.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cdaguerre picture cdaguerre  路  4Comments

tamalsaha picture tamalsaha  路  5Comments

pcrocker-pivotal picture pcrocker-pivotal  路  3Comments

jodh-intel picture jodh-intel  路  3Comments

nicholasdille picture nicholasdille  路  7Comments