saltstack-formulas / postgres-formula

http://docs.saltstack.com/en/latest/topics/development/conventions/formulas.html
Other
77 stars 283 forks source link

fix(archlinux): avoid nonetype error when grain is missing #306

Closed noelmcloughlin closed 3 years ago

noelmcloughlin commented 3 years ago

PR progress checklist (to be filled in by reviewers)


What type of PR is this?

Primary type

Secondary type

Does this PR introduce a BREAKING CHANGE?

No.

Related issues and/or pull requests

Describe the changes you're proposing

Fix for Archlinux - no osmajorreleasegrain ;-(

Pillar / config required to test the proposed changes

n/a

Debug log showing the bug being fixed

    Rendering SLS 'base:postgres.manage' failed: Jinja error: '>=' not supported between instances of 'NoneType' and 'int'
/var/cache/salt/minion/files/base/postgres/osfamilymap.yaml(66):
---
[...]
    humanname: PostgreSQL {{ repo.version }} $releasever - $basearch
    gpgcheck: 1
    gpgkey: 'https://download.postgresql.org/pub/repos/yum/RPM-GPG-KEY-PGDG-{{ release }}'
    baseurl: 'https://download.postgresql.org/pub/repos/yum/{{ repo.version }}/redhat/rhel-$releasever-$basearch'

{%- if grains.get('osmajorrelease') >= 7 %}    <======================
  pkg_python: python3-psycopg2
{%- endif %}

{% if repo.use_upstream_repo == true %}
  {% set data_dir = '/var/lib/pgsql/' ~ repo.version ~ '/data' %}
[...]
---
Traceback (most recent call last):
  File "/usr/lib/python3.9/site-packages/salt/utils/templates.py", line 498, in render_jinja_tmpl
    output = template.render(**decoded_context)
  File "/usr/lib/python3.9/site-packages/jinja2/environment.py", line 1090, in render
    self.environment.handle_exception()
  File "/usr/lib/python3.9/site-packages/jinja2/environment.py", line 832, in handle_exception
    reraise(*rewrite_traceback_stack(source=source))
  File "/usr/lib/python3.9/site-packages/jinja2/_compat.py", line 28, in reraise
    raise value.with_traceback(tb)
  File "<template>", line 1, in top-level template code
  File "/usr/lib/python3.9/site-packages/jinja2/environment.py", line 1155, in make_module
    return TemplateModule(self, self.new_context(vars, shared, locals))
  File "/usr/lib/python3.9/site-packages/jinja2/environment.py", line 1238, in __init__
    body_stream = list(template.root_render_func(context))
  File "/var/cache/salt/minion/files/base/postgres/map.jinja", line 2, in top-level template code
    {% import_yaml "postgres/osfamilymap.yaml" as osfamilymap %}
  File "/usr/lib/python3.9/site-packages/jinja2/environment.py", line 1155, in make_module
    return TemplateModule(self, self.new_context(vars, shared, locals))
  File "/usr/lib/python3.9/site-packages/jinja2/environment.py", line 1238, in __init__
    body_stream = list(template.root_render_func(context))
  File "/var/cache/salt/minion/files/base/postgres/osfamilymap.yaml", line 66, in top-level template code
    {%- if grains.get('osmajorrelease') >= 7 %}
TypeError: '>=' not supported between instances of 'NoneType' and 'int'

Documentation checklist

Testing checklist

Additional context

noelmcloughlin commented 3 years ago

Thanks. By habit I use more native Jina2 so just learning config.get way.

saltstack-formulas-travis commented 3 years ago

:tada: This PR is included in version 0.41.4 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket: