On 21 Oct, 14:29, bruno desthuilliers <bruno.desthuilli...@gmail.com>
wrote:
> On 21 oct, 15:05, Peter Bengtsson <pete...@gmail.com> wrote:
>
> > Suppose I've got this code:
>
> > # template.html
> > Info: {{ article_instance.count_words }} words
>
> > # models.py
> > class Article(models.Model):
> >    text = models.TextField()
> >    def count_words(self):
> >         raise AttributeError('debugging')
>
> <hs> a NotImplementedError would be more appropriate !-) </hs>
>
I don't know what <hs> means but it's just an example. I could have
written:
class Article(models.Model):
    ...
    def count_words(self):
         return some_complex_calculation(article=self)

> > Then, when I render that page I get:
> > Info:  words
>
> Did you actually tried with this exact code ? If yes, this contradicts
> the FineManual(tm):
> """
> If, during the method lookup, a method raises an exception, the
> exception will be propagated, unless the exception has an attribute
> silent_variable_failure whose value is True. If the exception does
> have a silent_variable_failure attribute, the variable will render as
> an empty string.
> (...)
> Note that django.core.exceptions.ObjectDoesNotExist, which is the base
> class for all Django database API DoesNotExist exceptions, has
> silent_variable_failure = True. So if you're using Django templates
> with Django model objects, any DoesNotExist exception will fail
> silently.
> """http://docs.djangoproject.com/en/dev/ref/templates/api/#rendering-a-c...
>
That's true for other exceptions only. E.g. ValueError or
ZeroDivisionError
I can't set silent_variable_failure=True on TemplateSyntaxError. This
is only applicable when you write your own exception sub classes.

> > When I want is a raised proper error so that I can spot the possible
> > bug in my system. How do I do that?
>
> Not tested, but this might be the answer:
>
> http://docs.djangoproject.com/en/dev/ref/settings/#debug-propagate-ex...
>
I don't know what that does. Perhaps it's related to views only, not
template rendering.
Setting it to True does NOT propagate AttributeErrors in templates
rendering.

> > If what you look up in the template doesn't exist I can accept that
> > Django, currently, prefers to just suppress it
>
> Actually, there's no "suppression", 
> cfhttp://docs.djangoproject.com/en/dev/ref/templates/api/#how-invalid-v...
>
There is.
http://code.djangoproject.com/ticket/11421

I've written a patch that solves it already. Now working on tests for
it.

> HTH
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to