Skip to content
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

[BUG] TypeError: object of type 'NoneType' has no len() #259

Open
arthurzenika opened this issue Nov 7, 2019 · 2 comments
Open

[BUG] TypeError: object of type 'NoneType' has no len() #259

arthurzenika opened this issue Nov 7, 2019 · 2 comments
Labels

Comments

@arthurzenika
Copy link
Contributor

Your setup

Formula commit hash / release tag

e8ed39a

Versions reports (master & minion)

Salt Version:
           Salt: 2019.2.2
 
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.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: Not Installed
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 2.7.13 (default, Nov 24 2017, 17:33:09)
   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.5 
         locale: UTF-8
        machine: x86_64
        release: 4.9.0-7-amd64
         system: Linux
        version: debian 9.5 


Bug details

Describe the bug

    Function: file.managed
        Name: /etc/nginx/sites-available/francearchives
      Result: False
     Comment: Unable to manage file: Jinja error: object of type 'NoneType' has no len()
              Traceback (most recent call last):
                File "/usr/lib/python2.7/dist-packages/salt/utils/templates.py", line 394, in render_jinja_tmpl
                  output = template.render(**decoded_context)
                File "/usr/lib/python2.7/dist-packages/jinja2/environment.py", line 989, in render
                  return self.environment.handle_exception(exc_info, True)
                File "/usr/lib/python2.7/dist-packages/jinja2/environment.py", line 754, in handle_exception
                  reraise(exc_type, exc_value, tb)
                File "<template>", line 29, in top-level template code
                File "<template>", line 10, in template
              TypeError: object of type 'NoneType' has no len()
              
              ; line 10
              
              ---
              [...]
              {{ key|indent(ind, True) }}{{ operator }}{{ value }}{{ delim }}{{ lb }}
                      {%- elif value is mapping -%}
                          {%- for k, v in value.items() -%}
                              {%- if v is number or v is string -%}
              {{ server_config([v], k, ind) }}
                              {%- elif v|length() > 0 and (v[0] is number or v[0] is string) -%}    <======================
              {{ server_config(v, k, ind) }}
                              {%- else -%}
              {{ lb }}{{ k|indent(ind, True) }} {{ '{' }}
              {{ server_config(v, '', ind + ind_increment) -}}
              {{ '}'|indent(ind, True) }}{{ lb }}
              [...]
              ---


@arthurzenika
Copy link
Contributor Author

I think I found the culprint in my pillars :

salt-call pillar.get nginx --output yaml 
[snip] 
        - map $host$uri $uuidredirect:
          - include: /srv/nfs/folder/uuid-redirect-map.conf
        - map $host$uri $newfauri: null
        - server:
          - listen:
            - 80
            - default_server
[snip]

the null is produced by a for loop that ends up empty in certain conditions. I've fixed my pillar mine code, but it might be interresting to render the jinja in nginx/files/default/server.conf more robust ?

@myii
Copy link
Member

myii commented Nov 12, 2019

@arthurlogilab Thanks for the report.

the null is produced by a for loop that ends up empty in certain conditions. I've fixed my pillar mine code, but it might be interresting to render the jinja in nginx/files/default/server.conf more robust ?

Sure, would you be willing to take this on?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants