``UndefinedError`` consistently. ``select_template`` will show the
undefined message in the list of attempts rather than the empty
string. :issue:`1037`
+- ``TemplateSyntaxError`` can be pickled. :pr:`1117`
+
Version 2.10.3
--------------
return u'\n'.join(lines)
+ def __reduce__(self):
+ # https://bugs.python.org/issue1692335 Exceptions that take
+ # multiple required arguments have problems with pickling.
+ # Without this, raises TypeError: __init__() missing 1 required
+ # positional argument: 'lineno'
+ return self.__class__, (self.message, self.lineno, self.name, self.filename)
+
class TemplateAssertionError(TemplateSyntaxError):
"""Like a template syntax error, but covers cases where something in the
"""
import pytest
+import pickle
import re
import sys
from traceback import format_exception
(jinja2\.exceptions\.)?TemplateSyntaxError: wtf
line 42''')
+ def test_pickleable_syntax_error(self, fs_env):
+ original = TemplateSyntaxError("bad template", 42, "test", "test.txt")
+ unpickled = pickle.loads(pickle.dumps(original))
+ assert str(original) == str(unpickled)
+ assert original.name == unpickled.name
+
def test_include_syntax_error_source(self, filesystem_loader):
e = Environment(loader=ChoiceLoader(
[