Skip to content

Can't use grains.list_present with complex(dict) types #39875

Closed

Description

@nw0428

Description of Issue/Question

A state like this:

service_ssh:
  grains.list_present:
    - name: services
    - value:
        - sshd:
            - hostname: localhost
            - port: 22

Will work the first time but not the second. The second time it throws the following:

        ID: service_ssh
    Function: grains.list_present
        Name: services
      Result: False
     Comment: An exception occurred in this state: Traceback (most recent call last):
                File "/usr/lib/python2.7/site-packages/salt/state.py", line 1734, in call
                  **cdata['kwargs'])
                File "/usr/lib/python2.7/site-packages/salt/loader.py", line 1651, in wrapper
                  return f(*args, **kwargs)
                File "/usr/lib/python2.7/site-packages/salt/states/grains.py", line 150, in list_present
                  if set(value).issubset(set(__salt__['grains.get'](name))):
              TypeError: unhashable type: 'dict'

Versions Report

Salt Version:
           Salt: 2016.3.5
 
Dependency Versions:
           cffi: 1.6.0
       cherrypy: 3.2.2
       dateutil: 2.5.3
          gitdb: Not Installed
      gitpython: Not Installed
          ioflo: Not Installed
         Jinja2: 2.8
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.4.8
   mysql-python: Not Installed
      pycparser: 2.14
       pycrypto: 2.6.1
         pygit2: Not Installed
         Python: 2.7.5 (default, Nov  6 2016, 00:28:07)
   python-gnupg: Not Installed
         PyYAML: 3.11
          PyZMQ: 15.3.0
           RAET: Not Installed
          smmap: Not Installed
        timelib: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.1.4
 
System Versions:
           dist: centos 7.3.1611 Core
        machine: x86_64
        release: 3.10.0-514.6.2.el7.x86_64
         system: Linux
        version: CentOS Linux 7.3.1611 Core

Activity

  1. Ch3LL commented on Mar 8, 2017

    @Ch3LL
    Contributor

    Looks like i'm able to replicate this.

    Here is a docker container for anyone that wants to quickly replicate this:

    1. docker run -it -v /home/ch3ll/git/salt/:/testing/ ch3ll/issues:39875 salt-call --local state.sls test -ldebug ( where /home/ch3ll/git/salt is a local cloned git repo of salt.)

    Looks like we need to get this fixed thanks

  2. added
    bug
    Core
    severity-medium
    P4
    on Mar 8, 2017
  3. added this to the Approved milestone on Mar 8, 2017
  4. stale commented on Sep 14, 2018

    @stale

    This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

    If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.

  5. mickenordin commented on Apr 26, 2019

    @mickenordin
    Contributor

    This seems to be an issue still, I am affected:
    In the state:

    grains.list_present:

    • name: ip_whitelist
    • value:
      • source: "0.0.0.0/0"
        port: 1234
      • source: "0.0.0.0/0"
        port: 5678

    From the log:

    2019-04-26T14:35:13.895806+02:00 example-lab-srv01.example.se salt-minion[577]: [ERROR ] An exception occurred in this state: Traceback (most recent call last):
    2019-04-26T14:35:13.896144+02:00 example-lab-srv01.example.se salt-minion[577]: File "/usr/lib/python3/dist-packages/salt/state.py", line 1933, in call
    2019-04-26T14:35:13.896346+02:00 example-lab-srv01.example.se salt-minion[577]: **cdata['kwargs'])
    2019-04-26T14:35:13.896539+02:00example-lab-srv01.example.se salt-minion[577]: File "/usr/lib/python3/dist-packages/salt/loader.py", line 1939, in wrapper
    2019-04-26T14:35:13.896731+02:00 example-lab-srv01.example.sesalt-minion[577]: return f(*args, **kwargs)
    2019-04-26T14:35:13.896921+02:00 example-lab-srv01.example.se salt-minion[577]: File "/usr/lib/python3/dist-packages/salt/states/grains.py", line 177, in list_present
    2019-04-26T14:35:13.897120+02:00 example-lab-srv01.example.se salt-minion[577]: if set(value).issubset(set(salt'grains.get')):
    2019-04-26T14:35:13.897302+02:00 example-lab-srv01.example.se salt-minion[577]: TypeError: unhashable type: 'dict'

  6. reopened this on May 5, 2019
  7. stale commented on May 5, 2019

    @stale

    Thank you for updating this issue. It is no longer marked as stale.

  8. mickenordin commented on May 9, 2019

    @mickenordin
    Contributor

    @dwoz I have submitted a PR that I think fixes this, and that has been reviewed. Do you have any idea of if and when that PR will be merged?

    Edit: The PR has been mered now, so this bug should be fixed 🎉

  9. Ch3LL commented on May 10, 2019

    @Ch3LL
    Contributor

    Thanks @mickenordin :) I'll go ahead and close

  10. added 3 commits that reference this issue on Oct 5, 2025
    e8d0d98
    651972e
    31504ee
  11. linked a pull request that will close this issuefix various bugs in list_present #68369on Oct 6, 2025
  12. added a commit that references this issue on Oct 21, 2025
    0e86012
  13. added 2 commits that reference this issue on Nov 4, 2025
    1905fc4
    e33eb5b
  14. added a commit that references this issue on Dec 1, 2025
    45b4700
  15. added a commit that references this issue on Dec 4, 2025
    375442c
  16. added a commit that references this issue on Dec 12, 2025
    9804725
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

    CoreP4State-Modulebugseverity-medium

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions