Using jinja2 as part of the tipfy framework, the provided appstats middleware causes a bad interaction with jinja2, resulting in an UndefinedError from jinja2. See http://code.google.com/p/tipfy-ext-appstats/issues/detail?id=1 for details.
I believe that this is weakly a bug on both sides. Appstats should catch the error, but jinja2 should not throw it when the undefined variable is not being used for in-template display. Thus, I think that getattr on runtime.Undefined should raise AttributeError, not UndefinedError, if the attribute is pseudo-private (starts with "_"). Here's the temporary patch I'm using starting at line 460 of runtime.py; please check this patch (Am I using @internalcode correctly? Do you agree with my reasoning?) and use it if appropriate:
__add__ = __radd__ = __mul__ = __rmul__ = __div__ = __rdiv__ = \
__truediv__ = __rtruediv__ = __floordiv__ = __rfloordiv__ = \
__mod__ = __rmod__ = __pos__ = __neg__ = __call__ = \
__getitem__ = __lt__ = __le__ = __gt__ = __ge__ = \
__int__ = __float__ = __complex__ = __pow__ = __rpow__ = \
Undefineds now support attribute errors for special attributes. This closed by 6a3e95d
Fixed. But only for "__" and I had to adapt a testcase to that changed behavior too. This will be in 2.6 and not in a bugfix release of 2.5 if there is another one.
Undefineds now support attribute errors for special attributes. This …