#1490 closed defect (invalid)
if __repr__ returns an int, {% debug %} gets an exception
Reported by: | Owned by: | Adrian Holovaty | |
---|---|---|---|
Component: | Template system | Version: | |
Severity: | normal | Keywords: | |
Cc: | Triage Stage: | Design decision needed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
(note: Russ Magee said to submit this as an enhancement... I think it's more of a bug, but... ok)
As part of developing my first Django app I'd make use of {% debug %}
often to see what's happening. I spent a while yesterday trying to
figure out why, just inserting a debug line in my template caused a
traceback of a rendering exception.
Turns out that I mistakenly had created a class with a repr that
returned a integer field instead of a "str". When I changed it to
"return str(self.value)" debug again worked fine.
I don't know if I'd call this a bug or not, but... I sure wish that
using a debug wouldn't protect itself from exceptions...
Yes, the docs do say:
Thus, you should always return a nice, human-readable string for
the object's repr.
I just don't think that debug should barf if an oject's
repr doesn't return a string.
I think that at the least, something like DEBUG should fail silently...
thanks
Change History (3)
comment:1 by , 19 years ago
comment:2 by , 19 years ago
Component: | Core framework → Template system |
---|---|
Type: | enhancement → defect |
The submitter is aware that __repr__
must return a string. The problem reported here is that {% debug %} does not give useful traceback.
The submitter said:
I don't know if I'd call this a bug or not, but... I sure wish that using a debug wouldn't protect itself from exceptions...
Hiding the cause of errors in a piece of code meant to help you track down errors would be a bug in my book :)
comment:3 by , 18 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
Maybe the code has changed since this ticket, but I can't see why debug
would cause a traceback now.
If anyone has this problem still, please provide some more info and we'll reopen.
From the Python docs on repr (http://docs.python.org/ref/customization.html):
"""The return value must be a string object."""