Skip to content

Specific state ID in formula causes TypeError during highstate. #53692

Closed

Description

@r-pufky

The following error occurs:

[DEBUG   ] An exception occurred in this state: string indices must be integers
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/salt/state.py", line 1933, in call
    **cdata['kwargs'])
  File "/usr/lib/python3/dist-packages/salt/loader.py", line 1939, in wrapper
    return f(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/salt/states/file.py", line 3932, in recurse
    keep.update(_gen_keep_files(name, require))
  File "/usr/lib/python3/dist-packages/salt/states/file.py", line 591, in _gen_keep_files
    if low['name'] == comp['file'] or low['__id__'] == comp['file']:
TypeError: string indices must be integers
[ERROR   ] An exception occurred in this state: Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/salt/state.py", line 1933, in call
    **cdata['kwargs'])
  File "/usr/lib/python3/dist-packages/salt/loader.py", line 1939, in wrapper
    return f(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/salt/states/file.py", line 3932, in recurse
    keep.update(_gen_keep_files(name, require))
  File "/usr/lib/python3/dist-packages/salt/states/file.py", line 591, in _gen_keep_files
    if low['name'] == comp['file'] or low['__id__'] == comp['file']:
TypeError: string indices must be integers

This occurs specifically when the state name in the formula starts with:

p_files_

Setup

formula/p/files.sls

{%- set files = salt['pillar.get']('p:files') -%}
{%- if files.recurse is defined %}
{%- for id, recurse_option in files.recurse.items() %}
p_files_recurse_{{ id }}:
  file.recurse:
    {%- for key, value in recurse_option.items() %}
      {%- if value is string %}
    - {{ key }}: '{{ value }}'
      {%- else %}
    - {{ key }}: {{ value }}
      {%- endif %}
    {%- endfor %}
  {%- endfor %}
{%- endif -%}

env/dev/top.sls

dev:
  test:
    - p.files

pillar/dev/test.sls

p:
  files:
    recurse:
      test_recurse_one:
        name: /test1
        source: salt://files/test1
        dir_mode: 0750
        file_mode: 0640
        user: root
        group: root
      test_recurse_two:
        name: /test2
        source: salt://files/test2
        require:
          - p_files_recurse_test_recurse_one
        dir_mode: 0755
        file_mode: 0444
        user: root
        group: root
        clean: True

Running a highstate test produces the following error:

----------
          ID: p_files_recurse_test_recurse_two
    Function: file.recurse
        Name: /test2
      Result: False
     Comment: An exception occurred in this state: Traceback (most recent call last):
                File "/usr/lib/python3/dist-packages/salt/state.py", line 1933, in call
                  **cdata['kwargs'])
                File "/usr/lib/python3/dist-packages/salt/loader.py", line 1939, in wrapper
                  return f(*args, **kwargs)
                File "/usr/lib/python3/dist-packages/salt/states/file.py", line 3932, in recurse
                  keep.update(_gen_keep_files(name, require))
                File "/usr/lib/python3/dist-packages/salt/states/file.py", line 591, in _gen_keep_files
                  if low['name'] == comp['file'] or low['__id__'] == comp['file']:
              TypeError: string indices must be integers
     Started: 23:43:35.589186
    Duration: 324.333 ms
     Changes:

Steps to Reproduce Issue

Run as is above. The error will be triggered.

However, changing the name of the state ID in the formula fixes the issue. I'm guessing I hit some internally used variable in salt during the highstate process?

Fix

Change the p_files_ to anything else, ala perms. No other changes (even formula name changes) are needed:

formula/p/files.sls

{%- set files = salt['pillar.get']('p:files') -%}
{%- if files.recurse is defined %}
{%- for id, recurse_option in files.recurse.items() %}
perms_recurse_{{ id }}:
  file.recurse:
    {%- for key, value in recurse_option.items() %}
      {%- if value is string %}
    - {{ key }}: '{{ value }}'
      {%- else %}
    - {{ key }}: {{ value }}
      {%- endif %}
    {%- endfor %}
  {%- endfor %}
{%- endif -%}

pillar/dev/test.sls

p:
  files:
    recurse:
      test_recurse_one:
        name: /test1
        source: salt://files/test1
        dir_mode: 0750
        file_mode: 0640
        user: root
        group: root
      test_recurse_two:
        name: /test2
        source: salt://files/test2
        require:
          - perms_recurse_test_recurse_one
        dir_mode: 0755
        file_mode: 0444
        user: root
        group: root
        clean: True

Re-running the highstate will now successfully run. My guess is there a namespace collision using files. I haven't seen this happen using other pillar keys with the same name as the formula.

Versions Report

(Provided by running salt --versions-report. Please also mention any differences in master/minion versions.)

minion

$ salt-minion --versions-report
Salt Version:
           Salt: 2019.2.0

Dependency Versions:
           cffi: Not Installed
       cherrypy: Not Installed
       dateutil: 2.6.1
      docker-py: Not Installed
          gitdb: Not Installed
      gitpython: Not Installed
          ioflo: Not Installed
         Jinja2: 2.10
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.5.6
   mysql-python: Not Installed
      pycparser: Not Installed
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 3.6.8 (default, Jan 14 2019, 11:02:34)
   python-gnupg: 0.4.1
         PyYAML: 3.12
          PyZMQ: 16.0.2
           RAET: Not Installed
          smmap: Not Installed
        timelib: Not Installed
        Tornado: 4.5.3
            ZMQ: 4.2.5

System Versions:
           dist: Ubuntu 18.04 bionic
         locale: UTF-8
        machine: x86_64
        release: 4.15.0-54-generic
         system: Linux
        version: Ubuntu 18.04 bionic

master

$ salt-master --versions-report
Salt Version:
           Salt: 2019.2.0

Dependency Versions:
           cffi: Not Installed
       cherrypy: Not Installed
       dateutil: 2.5.3
      docker-py: Not Installed
          gitdb: 2.0.0
      gitpython: 2.1.1
          ioflo: Not Installed
         Jinja2: 2.9.4
        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: Not Installed
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 3.5.3 (default, Sep 27 2018, 17:25:39)
   python-gnupg: Not Installed
         PyYAML: 3.12
          PyZMQ: 16.0.2
           RAET: Not Installed
          smmap: 2.0.1
        timelib: Not Installed
        Tornado: 4.4.3
            ZMQ: 4.2.1

System Versions:
           dist: debian 9.9
         locale: UTF-8
        machine: x86_64
        release: 4.9.0-9-amd64
         system: Linux
        version: debian 9.9

Activity

  1. changed the title [-]specific state ID in formula causes TypeError during highstate.[/-] [+]Specific state ID in formula causes TypeError during highstate.[/+] on Jul 3, 2019
  2. added
    Confirmed
    bug
    severity-low
    P4
    Core
    on Jul 3, 2019
  3. added this to the Approved milestone on Jul 3, 2019
  4. r-pufky commented on Jul 5, 2019

    @r-pufky
    Author

    Creating a separate formula SLS file to use for one of the cases resolves this error.

  5. removed
    P4
    on Jun 3, 2020
  6. added 2 commits that reference this issue on Jul 10, 2026
    02d61e5
    2dcef28
  7. added a commit that references this issue on Aug 4, 2026
    2d8d831
  8. added a commit that references this issue on Oct 27, 2026
    be340cc
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

    ConfirmedCoreState-Compilerbugseverity-low

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions