-
Operating System
Version of Python and packages in use at the time of the issue.
Minimum sample of YAML (or compatible) data necessary to trigger the issue
Complete steps to reproduce the issue when triggered via:
Expected Outcome
Actual Outcome
Screenshot(s), if Available |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
You've certainly found an edge-case in the code but I'm not sure my response is going to meet your expectation. I'm not even sure what should happen in this case because what you're attempting to do is to overwrite This is the expected behavior when attempting to convert a scalar into a complex data type: $ echo "foo: var" | yaml-set --change=foo.bar.key --value=value
CRITICAL: Cannot add PathSegmentTypes.KEY subreference to scalars at 'bar' in 'foo.bar.key'. An error is expected because converting data types is an unsafe operation. If I really wanted to convert a string into a map/hash, I would instead do this: $ echo "foo: var" | yaml-set --change=foo --delete | yaml-set --change=foo.bar.key --value=value
---
foo:
bar:
key: value As you can see, I have first deleted the scalar, then added an entirely new map/hash in its place. On the other hand, when your parent is a map, you get what you're after, like this: $ echo "foo: {}" | yaml-set --change=foo.bar.key --value=value
---
foo:
bar:
key: value
$ echo -e "foo:\n some: value" | yaml-set --change=foo.bar.key --value=value
---
foo:
some: value
bar:
key: value As you can see, the original target can be an empty or populated map/hash. As long as the data-types match, yamlpath will make the expected change. But In my experience, I've seen both. In Puppet/Hiera, I often see In the case of For now, the behavior you see from yamlpath is undefined. Anthon (the author of ruamel.yaml, on which yamlpath is based) and I didn't write yamlpath's change code with awareness of I'm going to convert this issue into a discussion to solicit more opinions on what yamlpath should do in this edge case. The question up for discussion becomes: When it comes to changing the value, should yamlpath treat |
Beta Was this translation helpful? Give feedback.
-
Thanks for such a comprehensive answer. I am the owner of the yaml file and have nothing against initialising the variable to an empty map, I wasn't aware of the typing underneath. going further however
but getting
is it double? not necessarily in one assignment regards |
Beta Was this translation helpful? Give feedback.
You've certainly found an edge-case in the code but I'm not sure my response is going to meet your expectation. I'm not even sure what should happen in this case because what you're attempting to do is to overwrite
null
with a map/hash. If yournull
were any other scalar, you'd get an appropriate error stating that yamlpath is unwilling to convert a scalar into a complex type. On the other hand, if yournull
were already a map/hash -- even an empty one -- you'd get the outcome you expect.This is the expected behavior when attempting to convert a scalar into a complex data type: