# Buggy code
def check_whitelist_blacklist(value, whitelist=None, blacklist=None):
    """
    Check a whitelist and/or blacklist to see if the value matches it.

    value
        The item to check the whitelist and/or blacklist against.

    whitelist
        The list of items that are white-listed. If ``value`` is found
        in the whitelist, then the function returns ``True``. Otherwise,
        it returns ``False``.

    blacklist
        The list of items that are black-listed. If ``value`` is found
        in the blacklist, then the function returns ``False``. Otherwise,
        it returns ``True``.

    If both a whitelist and a blacklist are provided, value membership
    in the blacklist will be examined first. If the value is not found
    in the blacklist, then the whitelist is checked. If the value isn't
    found in the whitelist, the function returns ``False``.
    """
    if blacklist is not None:
        if not hasattr(blacklist, "__iter__"):
            blacklist = [blacklist]
        for expr in blacklist:
            if expr_match(value, expr):
                return False

    if whitelist:
        if not hasattr(whitelist, "__iter__"):
            whitelist = [whitelist]
        for expr in whitelist:
            if expr_match(value, expr):
                return True
    else:
        return True

    return False


# 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 check_whitelist_blacklist(value, whitelist=None, blacklist=None):
    """
    Check a whitelist and/or blacklist to see if the value matches it.

    value
        The item to check the whitelist and/or blacklist against.

    whitelist
        The list of items that are white-listed. If ``value`` is found
        in the whitelist, then the function returns ``True``. Otherwise,
        it returns ``False``.

    blacklist
        The list of items that are black-listed. If ``value`` is found
        in the blacklist, then the function returns ``False``. Otherwise,
        it returns ``True``.

    If both a whitelist and a blacklist are provided, value membership
    in the blacklist will be examined first. If the value is not found
    in the blacklist, then the whitelist is checked. If the value isn't
    found in the whitelist, the function returns ``False``.
    """
    if blacklist is not None:
        if not isinstance(blacklist, list):
            blacklist = [blacklist]
        for expr in blacklist:
            if expr_match(value, expr):
                return False

    if whitelist:
        if not isinstance(whitelist, list):
            whitelist = [whitelist]
        for expr in whitelist:
            if expr_match(value, expr):
                return True
    else:
        return True

    return False