#26603: Can't use lazy objects as template names with cached loader anymore
---------------------------------+--------------------
     Reporter:  sephii           |      Owner:  nobody
         Type:  Bug              |     Status:  new
    Component:  Template system  |    Version:  1.9
     Severity:  Normal           |   Keywords:
 Triage Stage:  Unreviewed       |  Has patch:  0
Easy pickings:  0                |      UI/UX:  0
---------------------------------+--------------------
 It looks like commit
 
https://github.com/django/django/commit/bd145e7209a0e628cced10384bd6f62d65c0f211
 introduced a regression in Django 1.9.6. Before this commit, you could
 pass a lazy object to the {% extends %} tag and it would work just fine,
 however with Django 1.9.6 the following exception is raised:

 {{{
 Template error:
 In template /home/vagrant/ENV/local/lib/python2.7/site-
 packages/parler/templates/admin/parler/change_form.html, error at line 1
    sequence item 0: expected string, __proxy__ found   1 :  {% extends
 default_change_form_template|default:"admin/change_form.html" %}
    2 :
    3 : {% block field_sets %}
    4 : {% if language_tabs %}{% include "admin/parler/language_tabs.html"
 %}{% endif %}
    5 : {{ block.super }}
    6 : {% endblock %}
    7 :

 Traceback:

 File "/home/vagrant/ENV/local/lib/python2.7/site-
 packages/django/core/handlers/base.py" in get_response
   174.                     response =
 self.process_exception_by_middleware(e, request)

 File "/home/vagrant/ENV/local/lib/python2.7/site-
 packages/django/core/handlers/base.py" in get_response
   172.                     response = response.render()

 File "/home/vagrant/ENV/local/lib/python2.7/site-
 packages/django/template/response.py" in render
   160.             self.content = self.rendered_content

 File "/home/vagrant/ENV/local/lib/python2.7/site-
 packages/django/template/response.py" in rendered_content
   137.         content = template.render(context, self._request)

 File "/home/vagrant/ENV/local/lib/python2.7/site-
 packages/django/template/backends/django.py" in render
   95.             return self.template.render(context)

 File "/home/vagrant/ENV/local/lib/python2.7/site-
 packages/django/template/base.py" in render
   206.                     return self._render(context)

 File "/home/vagrant/ENV/local/lib/python2.7/site-
 packages/django/test/utils.py" in instrumented_test_render
   92.     return self.nodelist.render(context)

 File "/home/vagrant/ENV/local/lib/python2.7/site-
 packages/django/template/base.py" in render
   992.                 bit = node.render_annotated(context)

 File "/home/vagrant/ENV/local/lib/python2.7/site-
 packages/django/template/base.py" in render_annotated
   959.             return self.render(context)

 File "/home/vagrant/ENV/local/lib/python2.7/site-
 packages/django/template/loader_tags.py" in render
   151.         compiled_parent = self.get_parent(context)

 File "/home/vagrant/ENV/local/lib/python2.7/site-
 packages/django/template/loader_tags.py" in get_parent
   148.         return self.find_template(parent, context)

 File "/home/vagrant/ENV/local/lib/python2.7/site-
 packages/django/template/loader_tags.py" in find_template
   128.             template_name, skip=history,

 File "/home/vagrant/ENV/local/lib/python2.7/site-
 packages/django/template/engine.py" in find_template
   157.                         name, template_dirs=dirs, skip=skip,

 File "/home/vagrant/ENV/local/lib/python2.7/site-
 packages/django/template/loaders/cached.py" in get_template
   49.         key = self.cache_key(template_name, template_dirs, skip)

 File "/home/vagrant/ENV/local/lib/python2.7/site-
 packages/django/template/loaders/cached.py" in cache_key
   103.         return '-'.join(filter(bool, [template_name, skip_prefix,
 dirs_prefix]))

 Exception Type: TypeError at
 /en/admin/aldryn_newsblog/newsblogconfig/1/change/
 Exception Value: sequence item 0: expected string, __proxy__ found
 }}}

 You can easily reproduce the problem in a new project by using the
 following code in the urls.py file:

 {{{
 #!python
 from django.views.generic import TemplateView
 from django.utils.functional import lazy


 class TestView(TemplateView):
     template_name = 'home.html'

     def get_context_data(self, **kwargs):
         context = super(TestView, self).get_context_data(**kwargs)
         context['extended_template'] = lazy(lambda: 'base.html')
         return context

 urlpatterns = [
     url(r'^$', TestView.as_view()),
 ]
 }}}

 And create a file templates/home.html (and adapt the template dirs
 accordingly):

 {{{
 {% extends extended_template %}
 }}}

 The bug is present on master as well.

--
Ticket URL: <https://code.djangoproject.com/ticket/26603>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/049.8301986db0e1d1ece1ec1052277104d0%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to