#20745: Document the template language's silencing of TypeError ---------------------------------+------------------------------------ Reporter: robin | Owner: nobody Type: Bug | Status: new Component: Template system | Version: 1.5 Severity: Normal | Resolution: Keywords: | Triage Stage: Accepted Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 1 | UI/UX: 0 ---------------------------------+------------------------------------ Changes (by bmispelon):
* easy: 0 => 1 Comment: After some digging, I think I'm starting to understand what's happening here. When django finds a callable element in a template (which `{{ block.super }}` is, since it refers to a `BlockNode`'s `super` method), it attempts to call it (without passing any argument), wrapping the calling in a `try/except` and catching a `TypeError` (which happens when you call a function/method without enough arguments). In our case, a `TypeError` is raised from inside the function and subsequently caught and silenced in the `except` clause. Before 4397c587a43ff9bfddd295d48d850676778c6e77, any exception raised while rendering a template would be wrapped in a `TemplateSyntaxError`. This `TemplateSyntaxError` would then not be caught by the aforementionned `except TypeError` clause and would bubble up. Note that this would only happen with `settings.TEMPLATE_DEBUG = True` (this discrepancy between the two values of `TEMPLATE_DEBUG` is actually one of the reason why this change was introduced in the first place). This is therefore a limitation of django's implementation, which stems from the fact that it can't distinguish between a `TypeError` caused by calling a function without enough arguments and a `TypeError` raised from inside the function. This limitation is noted in a comment in the code [1], but as far as I can tell, it's not documented. I'm leaving this ticket open but I see it as a documentation issue, unless someone can come up with a clever way of side-stepping the problem but I'm not sure there is one. Since this details is somehow technical, I think a good place for it would be this section: https://docs.djangoproject.com/en/1.5/ref/templates/api /#variables-and-lookups [1] https://github.com/django/django/blob/028db9750357d504c55a7ac686c9abaa3c847ac6/django/template/base.py#L791-L794 -- Ticket URL: <https://code.djangoproject.com/ticket/20745#comment:5> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/063.48f41799859ee51e7c273376ed252249%40djangoproject.com. For more options, visit https://groups.google.com/groups/opt_out.