Opened 8 years ago

Closed 7 years ago

Last modified 7 years ago

#1490 closed defect (invalid)

if __repr__ returns an int, {% debug %} gets an exception

Reported by: gt-django@… Owned by: adrian
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: UI/UX:


(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...


Attachments (0)

Change History (3)

comment:1 Changed 8 years ago by gbrandl <g.brandl-nospam@…>

From the Python docs on repr (

"""The return value must be a string object."""

comment:2 Changed 8 years ago by jim-django@…

  • Component changed from Core framework to Template system
  • Type changed from enhancement to 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 Changed 7 years ago by SmileyChris

  • Resolution set to invalid
  • Status changed from new to 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.

Add Comment

Modify Ticket

Change Properties
<Author field>
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.