# Buggy code
def lst_avg(lst):
    """
    Returns the average value of a list.

    .. code-block:: jinja

        {% my_list = [1,2,3,4] -%}
        {{ set my_list | avg }}

    will be rendered as:

    .. code-block:: yaml

        2.5
    """
    if not isinstance(lst, collections.Hashable):
        return float(sum(lst) / len(lst))
    return float(lst)


# Traceback (jinja2.exceptions.TemplateAssertionError)
$ salt-ssh odin state.apply
[ERROR   ] Can't find varstack master_top
[ERROR   ] Rendering exception occurred
Traceback (most recent call last):
File "/home/andreas/code/contrib/salt/salt/utils/templates.py", line 378, in render_jinja_tmpl
template = jinja_env.from_string(tmplstr)
File "/home/andreas/code/contrib/salt/.venv/lib/python3.5/site-packages/jinja2/environment.py", line 880, in from_string
return cls.from_code(self, self.compile(source), globals, None)
File "/home/andreas/code/contrib/salt/.venv/lib/python3.5/site-packages/jinja2/environment.py", line 591, in compile
self.handle_exception(exc_info, source_hint=source_hint)
File "/home/andreas/code/contrib/salt/.venv/lib/python3.5/site-packages/jinja2/environment.py", line 780, in handle_exception
reraise(exc_type, exc_value, tb)
File "/home/andreas/code/contrib/salt/.venv/lib/python3.5/site-packages/jinja2/_compat.py", line 37, in reraise
raise value.with_traceback(tb)
File "<unknown>", line 4, in template
File "/home/andreas/code/contrib/salt/.venv/lib/python3.5/site-packages/jinja2/environment.py", line 543, in _generate
optimized=self.optimized)
File "/home/andreas/code/contrib/salt/.venv/lib/python3.5/site-packages/jinja2/compiler.py", line 82, in generate
generator.visit(node)
File "/home/andreas/code/contrib/salt/.venv/lib/python3.5/site-packages/jinja2/visitor.py", line 38, in visit
return f(node, *args, **kwargs)
File "/home/andreas/code/contrib/salt/.venv/lib/python3.5/site-packages/jinja2/compiler.py", line 754, in visit_Template
self.blockvisit(node.body, frame)
File "/home/andreas/code/contrib/salt/.venv/lib/python3.5/site-packages/jinja2/compiler.py", line 378, in blockvisit
self.visit(node, frame)
File "/home/andreas/code/contrib/salt/.venv/lib/python3.5/site-packages/jinja2/visitor.py", line 38, in visit
return f(node, *args, **kwargs)
File "/home/andreas/code/contrib/salt/.venv/lib/python3.5/site-packages/jinja2/compiler.py", line 1371, in visit_Assign
self.visit(node.node, frame)
File "/home/andreas/code/contrib/salt/.venv/lib/python3.5/site-packages/jinja2/visitor.py", line 38, in visit
return f(node, *args, **kwargs)
File "/home/andreas/code/contrib/salt/.venv/lib/python3.5/site-packages/jinja2/compiler.py", line 70, in new_func
return f(self, node, frame, **kwargs)
File "/home/andreas/code/contrib/salt/.venv/lib/python3.5/site-packages/jinja2/compiler.py", line 1578, in visit_Filter
self.fail('no filter named %r' % node.name, node.lineno)
File "/home/andreas/code/contrib/salt/.venv/lib/python3.5/site-packages/jinja2/compiler.py", line 315, in fail
raise TemplateAssertionError(msg, lineno, self.name, self.filename)
jinja2.exceptions.TemplateAssertionError: no filter named 'strftime'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/andreas/code/contrib/salt/salt/utils/templates.py", line 169, in render_tmpl
output = render_str(tmplstr, context, tmplpath)
File "/home/andreas/code/contrib/salt/salt/utils/templates.py", line 400, in render_jinja_tmpl
tmplstr)
salt.exceptions.SaltRenderError: Jinja syntax error: no filter named 'strftime'; line 4

---
# This state ensures that there is a daily backup in the form of a tarball in
# /var/backups/yyyy-mm-dd.tar.

{% set date = none | strftime('%Y-%m-%d') %}    <======================
{% set backup_dir = '/var/backups' %}
{% set script_path = '/usr/local/sbin/backup' %}

{{ backup_dir }}:
file.directory:
[...]

# Fixed code
def lst_avg(lst):
    """
    Returns the average value of a list.

    .. code-block:: jinja

        {% my_list = [1,2,3,4] -%}
        {{ set my_list | avg }}

    will be rendered as:

    .. code-block:: yaml

        2.5
    """
    salt.utils.versions.warn_until(
        "Neon",
        "This results of this function are currently being rounded."
        "Beginning in the Salt Neon release, results will no longer be "
        "rounded and this warning will be removed.",
        stacklevel=3,
    )

    if not isinstance(lst, collections.Hashable):
        return float(sum(lst) / len(lst))
    return float(lst)