Jacob Kaplan-Moss wrote: > On Sat, May 17, 2008 at 11:30 PM, James Bennett <[EMAIL PROTECTED]> wrote: >> The impression I get is that a lot of people rely on silent *variable* >> failure, but very few rely on silent *tag* failure. In fact, most >> real-world custom template tags I've seen are wired up to raise errors >> quite loudly, and the few times I've tried to write tags which fail >> silently it's been a laborious process that results in much more >> brittle code. > > Well said. I can't see making ``{{ foo.bar.baz }}`` fail loudly -- > it's just too big a change. It especially sucks when ``foo`` or > ``bar`` is a dynamically-constructed dictionary with variable keys.
Yes, probably too big a change to make ``{{ foo.bar.baz }}`` fail loudly at this point (even though there are things like the default filter and the firstof tag that could facilitate such a change). I would, however, be in favor for making the exception-catching a bit smarter here so that we don't suppress exceptions raised by a called method. For example, I'm ok with: {{ foo.calculate_number }} failing silently if no calculate_number attribute/method exists for foo, but if calculate_number is a method and happens to raise an exception when called, I want that to bubble up and fail loudly. Otherwise, hunting down the error becomes more of a chore. Besides, the motivation behind the silent behavior seems to be more for missing attributes. > I think taking a close look at built-in *tags*, though, is a good idea > -- in general, tags should fail loudly. There are exceptions, of > course; ``{% if dict.somekey %}`` is a common idiom which translates > to something like ``if dict.has_key('somekey') and dict.somekey`` -- > this is good. I also agree that, in many instances, tags should fail loudly, and that these types of failures need to be looked at on a tag by tag basis. The question then becomes, do we want to always raise these exceptions or do we want to only raise them if settings.TEMPLATE_DEBUG is True? Gary --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-developers?hl=en -~----------~----~----~----~------~----~------~--~---