As seen here, and I quote:
"Anchor names act somewhat like variable assignments: at any point in the document, the parser only knows about the anchors it’s seen so far, and a second anchor with the same name takes precedence. This means that aliases cannot refer to anchors that appear later in the document."
It should be possible to have anchors 'overwrite' each other (as it is possible here), but when implementing a YAML which does so ruamel gives me an duplicate anchor error.
Shouldn't this be possible?
(originally posted on 2016-08-18 at 08:01:56 by gerald-coddut <gerald-coddut@bitbucket>)
You are right about anchors not needing to be unique but not because of the link you post (which is irrelevant as it has nothing to do, nor refers to the YAML specification and arguably says the second or every second, with the same name takes precedence, whereas it is the last one that does take precedence). The relevant information is here:
"When composing a representation graph from serialized events, an alias node refers to the most recent node in the serialization having the specified anchor. Therefore, anchors need not be unique within a serialization."
This is a feature of PyYAML that ruamel.yaml inherited: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=515634
BTW Your second link does get me to some page with a captcha that doesn't let me proceed and your image doesn't show any code that fails. To expediate solving of a bug at least include self-contained example code (as code, never as a screenshot) that generates the error.
In this case it is clear to me what goes wrong, but what isn't is what code generates the same anchors for different objects? In Python using
ruamel.yamlor (PyYAML) this is AFAIK actually impossible to do.(originally posted on 2016-08-18 at 08:50:28)
None
(originally posted on 2016-08-18 at 08:51:02)
Ah you're right about the non-relevant information I opted, sorry about that. You're also right about showing you some code instead of that rather useless screenshot. Let me correct myself.
I'm loading my YAML from a file which look somewhat like:
I'm trying to parse the above file using this code:
Which gives me the error with the following stack trace:
Does this help somewhat?
Also; I've created a question at SO. I'm aware that this is rude, but I'd like to ask if you could take a little peek at the question.
I'm struggling a bit with YAML. Starting to think I'm trying to make it go trough impossible hoops.
(originally posted on 2016-08-18 at 10:19:08 by gerald-coddut <gerald-coddut@bitbucket>)
Hi Gerald,
Thanks for the update and for reporting. I had already made my own (failing) example, and implemented a solution, but it is always good to test with something someone else came up with, in case I just use some corner case.
This now loads (using ruamel.yaml 0.12.3):
It now gives a warning (which can be suppressed by commenting out the 3 commented lines).
I would write your example:
to make sure the file is actually closed (and using
withis better than callingf.close())If you have questions, which are not really bugs, post on stackoverflow and tag with
ruamel.yaml. Any bugs are of course "welcome" here ;-)(originally posted on 2016-08-18 at 10:56:44)
fixed in 0.12.3 please confirm by closing this issue
(originally posted on 2016-08-18 at 10:59:02)
I've confirmed that this works as of 0.12.3, will close the issue with that reason.
Thanks for responding and resolving the issue this quickly!
(originally posted on 2016-08-18 at 11:51:37 by gerald-coddut <gerald-coddut@bitbucket>)
(originally posted on 2016-08-18 at 11:51:54 by gerald-coddut <gerald-coddut@bitbucket>)
with ruamel.yaml version 0.15.34 this happens again and behaves the same way as pyaml does, again
fails with
issue on pyaml https://github.com/yaml/pyyaml/issues/100
(originally posted on 2017-11-25 at 05:23:46 by Nikky <nikky@bitbucket>)
Same issue here, plus this is using the
yqcommand line tool.Which sadly makes my use case with anchors unusable
(originally posted on 2019-01-09 at 17:25:48 by Clement Desiles <clement-desiles-hoppen@bitbucket>)
@NikkyAi The issue is caused by libyaml, so until that library is updated, you should do
yaml = YAML(typ='safe', pure=True)or use the default (yaml = YAML()) . (Sorry, but had not seen your comment before, it is in general better to re-open a closed issue if you find it no longer is fixed. Or submit a new issue, and refer to the closed issue. Bitbucket doesn't always notify me on comments added to closed issues.@clement-desiles-hoppen I don't know what you are trying to say, If "this" refers to ruamel.yaml then I can guarantee that it is not using
yq. If this refers to the issue gerald-coddut submitted or the comment by Nikky (is that what you mean by same issue?) then I don't see how they are usingyq. I would appreciate you taking your time, in making any comments you post less cryptic and/or ambiguous. That way I don't have to waste any time guessing (let alone reproducing and not even thinking about resolving) what you are writing about.(originally posted on 2019-01-09 at 19:12:47)
Hi Anthon, sorry for the late answer, and the cryptic message.
I'm using
jq(https://github.com/stedolan/jq) and a yaml wrapper arround it, calledyq(https://pypi.org/project/yq/), which is a great tool to manipulate yaml data.I wrongly supposed
yqwas based onruaml.yaml, in fact it seems it's still based onPyYAML:Using the gerald-coduct's example above, I've this result:
Here is the explanation, sorry for the noise!
(originally posted on 2019-03-26 at 09:26:10 by Clement Desiles <clement-desiles-hoppen@bitbucket>)