[2.0.x] Fixed #29617 -- Fixed Template crash if template_string is lazy.

Regression in 3a148f958d.
Backport of 9f3b9ffd51 from master.
This commit is contained in:
Dražen Odobašić 2018-07-31 15:57:11 +02:00 committed by Tim Graham
parent c26f001967
commit 253f1b74da
3 changed files with 12 additions and 2 deletions

View File

@ -156,7 +156,7 @@ class Template:
self.name = name
self.origin = origin
self.engine = engine
self.source = template_string
self.source = str(template_string) # May be lazy.
self.nodelist = self.compile_nodelist()
def __iter__(self):

View File

@ -11,3 +11,6 @@ Bugfixes
* Fixed a regression in Django 2.0.7 that broke the ``regex`` lookup on MariaDB
(even though MariaDB isn't officially supported) (:ticket:`29544`).
* Fixed a regression where ``django.template.Template`` crashed if the
``template_string`` argument is lazy (:ticket:`29617`).

View File

@ -1,5 +1,12 @@
from django.template.base import VariableDoesNotExist
from django.template import Context, Template, VariableDoesNotExist
from django.test import SimpleTestCase
from django.utils.translation import gettext_lazy
class TemplateTests(SimpleTestCase):
def test_lazy_template_string(self):
template_string = gettext_lazy('lazy string')
self.assertEqual(Template(template_string).render(Context()), template_string)
class VariableDoesNotExistTests(SimpleTestCase):