[Django] #21707: Uninformative error if block.super is used inside the block tag of a base template

19 views
Skip to first unread message

Django

unread,
Dec 30, 2013, 5:38:49 AM12/30/13
to django-...@googlegroups.com
#21707: Uninformative error if block.super is used inside the block tag of a base
template
--------------------------------------+--------------------
Reporter: mitar | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Template system | Version: 1.4
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+--------------------
If `block.super` is used inside the block tag of a base template, an
uninformative error is thrown:

{{{
'BlockNode' object has no attribute 'context'
}}}

It is thrown in `super` method when doing:

{{{
render_context = self.context.render_context
}}}

I think code should check for missing `self.context` and throw a more
informative exception.

--
Ticket URL: <https://code.djangoproject.com/ticket/21707>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jan 2, 2014, 8:21:52 PM1/2/14
to django-...@googlegroups.com
#21707: Uninformative error if block.super is used inside the block tag of a base
template
--------------------------------------+------------------------------------

Reporter: mitar | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Template system | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by timo):

* needs_better_patch: => 0
* stage: Unreviewed => Accepted
* version: 1.4 => master
* needs_tests: => 0
* needs_docs: => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/21707#comment:1>

Django

unread,
Jun 15, 2014, 3:39:53 AM6/15/14
to django-...@googlegroups.com
#21707: Uninformative error if block.super is used inside the block tag of a base
template
-------------------------------------+-------------------------------------
Reporter: mitar | Owner:
Type: | anubhav9042
Cleanup/optimization | Status: assigned

Component: Template system | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by anubhav9042):

* owner: nobody => anubhav9042
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/21707#comment:2>

Django

unread,
Jul 13, 2014, 4:57:38 AM7/13/14
to django-...@googlegroups.com
#21707: Uninformative error if block.super is used inside the block tag of a base
template
-------------------------------------+-------------------------------------
Reporter: mitar | Owner:
Type: | anubhav9042
Cleanup/optimization | Status: assigned
Component: Template system | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by anubhav9042):

* has_patch: 0 => 1


Comment:

I have added a small patch which raises TemplateSyntaxError.

--
Ticket URL: <https://code.djangoproject.com/ticket/21707#comment:3>

Django

unread,
Jul 16, 2014, 1:51:42 PM7/16/14
to django-...@googlegroups.com
#21707: Uninformative error if block.super is used inside the block tag of a base
template
-------------------------------------+-------------------------------------
Reporter: mitar | Owner:
Type: | anubhav9042
Cleanup/optimization | Status: assigned
Component: Template system | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timo):

* cc: timo (added)
* needs_better_patch: 0 => 1


Comment:

I would hope there's a more specific way to detect this problem than
catching all AttributeErrors. Also `TemplateSyntaxError` should include a
helpful message.

--
Ticket URL: <https://code.djangoproject.com/ticket/21707#comment:4>

Django

unread,
Jul 17, 2014, 7:28:54 AM7/17/14
to django-...@googlegroups.com
#21707: Uninformative error if block.super is used inside the block tag of a base
template
-------------------------------------+-------------------------------------
Reporter: mitar | Owner:
Type: | anubhav9042
Cleanup/optimization | Status: assigned
Component: Template system | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by anubhav9042):

Sure.
I just had a quick look. I'll add a better patch soon.

--
Ticket URL: <https://code.djangoproject.com/ticket/21707#comment:5>

Django

unread,
Jul 23, 2014, 3:42:58 PM7/23/14
to django-...@googlegroups.com
#21707: Uninformative error if block.super is used inside the block tag of a base
template
-------------------------------------+-------------------------------------
Reporter: mitar | Owner:
Type: | anubhav9042
Cleanup/optimization | Status: assigned
Component: Template system | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by anubhav9042):

Changed the position where I handled `AttributeError`

--
Ticket URL: <https://code.djangoproject.com/ticket/21707#comment:6>

Django

unread,
Jul 23, 2014, 5:51:58 PM7/23/14
to django-...@googlegroups.com
#21707: Uninformative error if block.super is used inside the block tag of a base
template
-------------------------------------+-------------------------------------
Reporter: mitar | Owner:
Type: | anubhav9042
Cleanup/optimization | Status: assigned
Component: Template system | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by timo):

Rather than try/except, it would probably be better to do:
{{{
if not hasattr(self, 'context'):
raise TemplateSyntaxError(...)
}}}
And make the message less definitive (e.g. include the original exception
message and add "Did you use {{ block.super }} in a base template?". I am
not sure, but there might be other cases where context could be missing so
including the original exception could be helpful just in case.

--
Ticket URL: <https://code.djangoproject.com/ticket/21707#comment:7>

Django

unread,
Jul 24, 2014, 2:07:19 PM7/24/14
to django-...@googlegroups.com
#21707: Uninformative error if block.super is used inside the block tag of a base
template
-------------------------------------+-------------------------------------
Reporter: mitar | Owner:
Type: | anubhav9042
Cleanup/optimization | Status: assigned
Component: Template system | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by anubhav9042):

* needs_better_patch: 1 => 0


Comment:

https://github.com/django/django/pull/2949

--
Ticket URL: <https://code.djangoproject.com/ticket/21707#comment:8>

Django

unread,
Jul 24, 2014, 2:25:10 PM7/24/14
to django-...@googlegroups.com
#21707: Uninformative error if block.super is used inside the block tag of a base
template
-------------------------------------+-------------------------------------
Reporter: mitar | Owner:
Type: | anubhav9042
Cleanup/optimization | Status: closed

Component: Template system | Version: master
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"b1abfb3c59467d0bb088e19be76fc42fcb570835"]:
{{{
#!CommitTicketReference repository=""
revision="b1abfb3c59467d0bb088e19be76fc42fcb570835"
Fixed #21707 -- Added helpful error message when using {{ block.super }}
in base template.

Thanks mitar for the suggestion.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/21707#comment:9>

Reply all
Reply to author
Forward
0 new messages