On Mar 6, 10:40 am, bruno desthuilliers <bruno.desthuilli...@gmail.com> wrote: > On Mar 6, 7:07 am, Aryeh Leib Taurog <v...@aryehleib.com> wrote: > > > Sometimes self.get_another_object() returns an object which doesn't > > have attribute 'x' so my_title() raises an AttributeError exception. > > Under Django 1.2.4 the template renders as 'Generic Title,' but under > > 1.3.1 I get a server error. > > Did you check the DEBUG and TEMPLATE_DEBUG flags in your settings ?
Actually that only seems to affect which exception class is raised with django 1.3.x. Under django 1.2.x it doesn't have any effect. I finally had a moment to put together the following script which demonstrates the issue in isolation. Perhaps the 1.2.x behavior is not "correct." Nonetheless, this is a very significant behavioral change which broke at least one page (that I know of) on our production site. I would expect it should be very clearly documented somewhere. # test.py -------------- import django from django.conf import settings from django.template import Context, Template import sys debug = ('debug' in sys.argv) settings_dict = dict(DEBUG=debug, TEMPLATE_DEBUG=debug) settings.configure(**settings_dict) class Foo: def no_exception(self): return "Method" def exception(self): raise AttributeError c = Context({"o": Foo()}) templates = ("{{ o.no_exception }}", "{{ o.exception }}") print "Django version: %s" % django.get_version() print "settings: %r" % settings_dict try: for ttext in templates: t = Template(ttext) print repr((ttext, t.render(c))) except Exception, e: print "Caught exception: %r" % e # ------------- Here's what I get when I run this with different versions of django: $ python test.py Django version: 1.2.7 settings: {'DEBUG': False, 'TEMPLATE_DEBUG': False} ('{{ o.no_exception }}', u'Method') ('{{ o.exception }}', u'') $ python test.py debug Django version: 1.2.7 settings: {'DEBUG': True, 'TEMPLATE_DEBUG': True} ('{{ o.no_exception }}', u'Method') ('{{ o.exception }}', u'') $ python test.py Django version: 1.3 settings: {'DEBUG': False, 'TEMPLATE_DEBUG': False} ('{{ o.no_exception }}', u'Method') Caught exception: AttributeError() $ python test.py debug Django version: 1.3 settings: {'DEBUG': True, 'TEMPLATE_DEBUG': True} ('{{ o.no_exception }}', u'Method') Caught exception: TemplateSyntaxError(u'Caught AttributeError while rendering: ',) -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.