-
Notifications
You must be signed in to change notification settings - Fork 526
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
Inconsistent behavior with constructors #120
Comments
I'm not sure if it's really defined what should happen in this case. A constructor might return something that is not a mapping (an object, a list, a scalar, ...). So I could imagine that pyyaml simply skips resolving tags for merged aliases. Do you have a real world use case example for this? (note that I don't know the pyyaml implementation, but I'm writing a YAML processor in perl, and with my current plan the result would be the same. edit: actually I'm not sure about how this would be handled. the question is, if the resolving of the tag has already happened or not) |
I see, hmmm, I didn't think of that.
Yes, here we are using YAML files to provide templates from our lib that are "imported" by our apps. What we try to do here is to use !tags inside our templates to allow app developers to override certain values inside the templates. The use of these !tags and constructors (as per the example) would allow us to "inject" the overridden values into the templates. |
After looking at constructor code, this is what happens: Example (case2):
Right after it's loaded, looks like this:
After the root map node is contructed, looks like this:
NOTE: the !construct tags are processed while traversing the document and constructing the parent nodes (parent of the tagged nodes), so at this point the second !construct tag has not been processed yet. Right after that, it reaches the merge node and the key-merge is flatten, looking like this:
NOTE: the flatten step occurs right before the contruct step and completely ignores the tags. So, there seems to be 2 issues, 1) flatten step ignores the tags and/or, 2) (even if the tags were not lost during flatten) the tags are processed only when constructing the parents node, but since the parent node of the merge node has already been constructed, the resulting node of the merge is never "constructed", thus, the its !constructed would never be processed anyways. To me, it sounds like these tags should be processed before the merge happens, but that is not how pyyaml traverses the document. I wonder if @xitology has other ideas for what to do with this case. |
I noticed the following inconsistency:
The output is:
Shouldn't
case1
andcase2
produce identical output? Looks like the combination<<: *anchor
ends up with the constructor getting ignored.Environment:
The text was updated successfully, but these errors were encountered: