-
Notifications
You must be signed in to change notification settings - Fork 23.8k
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
Don't convert nulls to strings. #10957
Conversation
@abadger thoughts on this change? |
54aa0c0
to
8348a4e
Compare
8348a4e
to
52ad9c4
Compare
we might need to reformat this as devel has changed drastically. |
@bcoca looks like it's been rebased since the switchover to v2 so it's probably okay in that regard. I've tested and it does work without further rebasing. One thing I've noted is that implicit nulls are also changed by this PR:
the variable "empty" is also changed from empty string to null. Not sure if that behaviour change might break some things. @bcoca suggested that we make this configurable in the config file and set it to empty string by default for backwards compat. |
@abadger this matches the behaviour of how python generally treats an empty value in yaml. I would think that we would want to match that. If it seems like a dangerous change, I'm happy to put it behind a config flag. Can you point me to an example that I can work from?
|
@feanil, yeah... the problem being backwards compatibility :-( Since empty values have implicitly mapped to an empty string for such a long time there's probably quite a few playbooks that will break from that behaviour changing. Making it a configurable value would hopefully let us change the default from backwards compatible to more in line with what other things do in the future. @bcoca do you happpen to know of a good simple config setting that feanil can use as an example of writing one for this feature? |
fail_on_undefined had very similar scope and fix |
@feanil, are you planning to resubmit this with a config-variable guard? (Maybe something like |
@amenonsen yes, I'm hoping to get some time in the next week or so to work on this. |
52ad9c4
to
31bc602
Compare
@bcoca @amenonsen Added a commit to make this configurable per your suggestions, please let me know if there is anything more I should do. |
@feanil cool. So the ChangeLog and the code don't agree here. the ChangeLog says that the default has changed to None but the code defaults to returning an empty string. The core team talked about this for a while this morning and we decided that since there's a need to specify a None in playbooks that consistently propogates out to module parameters that we'd be okay with switching the default for v2 and then documenting it prominently. So three changes and then we can merge:
|
d7826ed
to
5c5f31e
Compare
5c5f31e
to
a60f865
Compare
This change is similar to ansible#10465 It extends the logic there to also support none types. Right now if you have a '!!null' in yaml, and that var gets passed around, it will get converted to a string. eg. defaults/main.yml ``` ENABLE_AWESOME_FEATURE: !!null # Yaml Null OTHER_CONFIG: secret1: "so_secret" secret2: "even_more_secret" CONFIG: hostname: "some_hostname" features: awesame_feature: "{{ ENABLE_AWESOME_FEATURE}}" secrets: "{{ OTHER_CONFIG }}" ``` If you output `CONFIG` to json or yaml, the feature flag would get represented in the output as a string instead of as a null, but secrets would get represented as a dictionary. This is a mis-match in behaviour where some "types" are retained and others are not. This change should fix the issue. I also updated the template test to test for this and made the changes to v2. Added a changelog entry specifically for the change from empty string to null as the default. Made the null representation configurable. It still defaults to the python NoneType but can be overriden to be an emptystring by updating the DEFAULT_NULL_REPRESENTATION config.
a60f865
to
892e230
Compare
Rebased to be mergable again. |
Don't convert nulls to strings.
Thanks @feanil ! Merged. MergedHi! This has been merged in, and will also be included in the next major release. If you or anyone else has any further questions, please let us know by stopping by one of the two mailing lists, as appropriate:
Because this project is very active, we're unlikely to see comments made on closed tickets, but the mailing list is a great way to ask questions, or post if you don't think this particular Thank you! |
This change is similar to #10465
It extends the logic there to also support none types. Right now if you have
a '!!null' in yaml, and that var gets passed around, it will get converted to
a string.
eg. defaults/main.yml
If you output
CONFIG
to json or yaml, the feature flag would get represented in the outputas a string instead of as a null, but secrets would get represented as a dictionary. This is
a mis-match in behaviour where some "types" are retained and others are not. This change
should fix the issue.
I also updated the template test to test for this and made the changes to v2.
Added a changelog entry.
@abadger A type we missed when we made the change for numbers and booleans.