Skip to content

file.serialize JSON w/merge_if_exists fails if top-level is not a dict #41209

Description

@The-Loeki

Description of Issue/Question

file.serialize has the merge_if_exists option.
When serializing to JSON, it apparently assumes the top level to be a dict.
While this is of course extremely common, it's not always true, and when it's not, the serializer crashes.

Steps to Reproduce Issue

SLS:

my-json-list:
  file.serialize:
    - name: /tmp/list.json
    - formatter: json
    - merge_if_exists: True
    - dataset:
        - tea
        - pot
# cat /tmp/list.json
[  "tea", "kettle" ]
          ID: my-json-list
    Function: file.serialize
        Name: /tmp/list.json
      Result: False
     Comment: An exception occurred in this state: Traceback (most recent call last):
                File "/usr/lib/python2.7/dist-packages/salt/state.py", line 1746, in call
                  **cdata['kwargs'])
                File "/usr/lib/python2.7/dist-packages/salt/loader.py", line 1704, in wrapper
                  return f(*args, **kwargs)
                File "/usr/lib/python2.7/dist-packages/salt/states/file.py", line 5144, in serialize
                  merged_data = salt.utils.dictupdate.merge_recurse(existing_data, dataset)
                File "/usr/lib/python2.7/dist-packages/salt/utils/dictupdate.py", line 82, in merge_recurse
                  return update(copied, obj_b, merge_lists=merge_lists)
                File "/usr/lib/python2.7/dist-packages/salt/utils/dictupdate.py", line 35, in update
                  raise TypeError('Cannot update using non-dict types in dictupdate.update()')
              TypeError: Cannot update using non-dict types in dictupdate.update()
     Started: 11:32:11.537613
    Duration: 3.339 ms
     Changes:   

Versions Report

Salt Version:
           Salt: 2016.11.4
 
Dependency Versions:
           cffi: Not Installed
       cherrypy: Not Installed
       dateutil: 2.4.2
      docker-py: Not Installed
          gitdb: Not Installed
      gitpython: Not Installed
          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: Not Installed
        timelib: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.1.4
 
System Versions:
           dist: Ubuntu 16.04 xenial
        machine: x86_64
        release: 4.10.0-20-generic
         system: Linux
        version: Ubuntu 16.04 xenial

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    PlatformRelates to OS, containers, platform-based utilities like FS, system based appsState-Modulebugbroken, incorrect, or confusing behaviorseverity-medium3rd level, incorrect or bad functionality, confusing and lacks a work around

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions