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

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

Closed
OnkelTem opened this issue Jun 15, 2020 · 8 comments
Closed
Labels
Milestone

Comments

@OnkelTem
Copy link

OnkelTem commented Jun 15, 2020

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.

@OnkelTem OnkelTem added the bug label Jun 15, 2020
@mikefarah
Copy link
Owner

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

@OnkelTem
Copy link
Author

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

@mikefarah
Copy link
Owner

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

@OnkelTem
Copy link
Author

OnkelTem commented Jun 18, 2020

@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/
—it works just fine, so I believe it's definitely a bug.

@OnkelTem
Copy link
Author

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

@OnkelTem
Copy link
Author

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:

@mikefarah mikefarah reopened this Jun 22, 2020
@mikefarah mikefarah changed the title --explodeAnchors / -X doesn't work in 3.3.1 and 3.3.2 --explodeAnchors / -X doesn't explode keys (work in 3.3.1 and 3.3.2) Jun 22, 2020
@mikefarah
Copy link
Owner

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.

@mikefarah mikefarah added this to the 3.3.3 milestone Jun 22, 2020
@mikefarah
Copy link
Owner

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