From 9f3b9ffd51c71d96728df9ee16f5a57c6f3b315d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dra=C5=BEen=20Odoba=C5=A1i=C4=87?= Date: Tue, 31 Jul 2018 15:57:11 +0200 Subject: [PATCH] Fixed #29617 -- Fixed Template crash if template_string is lazy. Regression in 3a148f958dddd97c1379081118c30fbede6b6bc4. --- django/template/base.py | 2 +- docs/releases/2.0.8.txt | 3 +++ tests/template_tests/test_base.py | 9 ++++++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/django/template/base.py b/django/template/base.py index c2376ff5a5..f6a60ecdf7 100644 --- a/django/template/base.py +++ b/django/template/base.py @@ -152,7 +152,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): diff --git a/docs/releases/2.0.8.txt b/docs/releases/2.0.8.txt index c83a60cf81..16f4f4aede 100644 --- a/docs/releases/2.0.8.txt +++ b/docs/releases/2.0.8.txt @@ -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`). diff --git a/tests/template_tests/test_base.py b/tests/template_tests/test_base.py index 3bc857abee..475a647dd2 100644 --- a/tests/template_tests/test_base.py +++ b/tests/template_tests/test_base.py @@ -1,5 +1,12 @@ -from django.template.base import Variable, VariableDoesNotExist +from django.template import Context, Template, Variable, 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):