Opened 11 years ago
Closed 10 years ago
#21707 closed Cleanup/optimization (fixed)
Uninformative error if block.super is used inside the block tag of a base template
Reported by: | Mitar | Owned by: | ANUBHAV JOSHI |
---|---|---|---|
Component: | Template system | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Tim Graham | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
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.
Attachments (2)
Change History (11)
comment:1 by , 11 years ago
Triage Stage: | Unreviewed → Accepted |
---|---|
Version: | 1.4 → master |
comment:2 by , 11 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
by , 10 years ago
Attachment: | 21707.patch added |
---|
comment:3 by , 10 years ago
Has patch: | set |
---|
comment:4 by , 10 years ago
Cc: | added |
---|---|
Patch needs improvement: | set |
I would hope there's a more specific way to detect this problem than catching all AttributeErrors. Also TemplateSyntaxError
should include a helpful message.
by , 10 years ago
Attachment: | 21707_patch2.diff added |
---|
comment:7 by , 10 years ago
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.
comment:8 by , 10 years ago
Patch needs improvement: | unset |
---|
comment:9 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
I have added a small patch which raises TemplateSyntaxError.