﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
15329	get_template_names() should use getattr() on object	tribaal@…	nobody	"I discovered by writing unit tests for a subclass of DetailView that the get_template_names() method of SingleObjectTemplateResponseMixin (django.views.generic.detail) does not use getattr to access the object attribute.

In the context of writing tests for a subclass overriding (and/or extending) the behavior of get_template_names, ""object"" may not be present.

The following patch solves the problem permanently:

{{{
--- a/django/views/generic/detail.py
+++ b/django/views/generic/detail.py
@@ -119,14 +119,15 @@ class SingleObjectTemplateResponseMixin(TemplateResponseMixin):
         # If self.template_name_field is set, grab the value of the field
         # of that name from the object; this is the most specific template
         # name, if given.
-        if self.object and self.template_name_field:
+        if (getattr(self, 'object', None) and 
+            getattr(self, 'template_name_field', None)):
             name = getattr(self.object, self.template_name_field, None)
             if name:
                 names.insert(0, name)
 
         # The least-specific option is the default <app>/<model>_detail.html;
         # only use this if the object in question is a model.
-        if hasattr(self.object, '_meta'):
+        if hasattr(self, 'object') and hasattr(self.object, '_meta'):
             names.append(""%s/%s%s.html"" % (
                 self.object._meta.app_label,
                 self.object._meta.object_name.lower(),
}}}"		closed	Generic views	1.3-beta		invalid			Unreviewed	1	0	0	0	0	0
