salt: YAML loading and serializing does not handle None properly

Description of Issue/Question

I am using import_yaml to load a YAML file that has some keys with empty values (Ex.: key:), then use file.serialize to write it to a YAML file again. But all keys that previously had no values, now have a None in place, which is a valid string, but not a valid YAML empty value.

This is causing problems because the program that expects an empty or decimal value is getting a string instead.

Setup

{% import_yaml "defaults.yaml" as defaults %} 

{{ sls }}~config:
  file.serialize:
    - name: /etc/config.yaml
    - show_changes: true
    - formatter: yaml
    - backup: minion
    - dataset: {{ defaults }}

Steps to Reproduce Issue

Can be verified using state.show_sls.

Versions Report

Salt Version:
           Salt: 2017.7.1
 
Dependency Versions:
           cffi: Not Installed
       cherrypy: Not Installed
       dateutil: 2.4.2
      docker-py: Not Installed
          gitdb: 0.6.4
      gitpython: 1.0.1
          ioflo: Not Installed
         Jinja2: 2.8
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: 1.0.3
   msgpack-pure: Not Installed
 msgpack-python: 0.4.6
   mysql-python: Not Installed
      pycparser: Not Installed
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 2.7.12 (default, Nov 19 2016, 06:48:10)
   python-gnupg: Not Installed
         PyYAML: 3.11
          PyZMQ: 15.2.0
           RAET: Not Installed
          smmap: 0.9.0
        timelib: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.1.4
 
System Versions:
           dist: Ubuntu 16.04 xenial
         locale: UTF-8
        machine: x86_64
        release: 4.4.0-96-generic
         system: Linux
        version: Ubuntu 16.04 xenial

About this issue

  • Original URL
  • State: open
  • Created 7 years ago
  • Reactions: 6
  • Comments: 15 (7 by maintainers)

Most upvoted comments

If it is loaded as empty from a YAML, it should remain empty in the end, and that is the case.

One idea is to change the serializer behaviour by introducing per-format options.