Opened 18 years ago

Closed 17 years ago

Last modified 17 years ago

#1490 closed defect (invalid)

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

Reported by: gt-django@… 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 gbrandl <g.brandl-nospam@…>, 18 years ago

From the Python docs on repr (http://docs.python.org/ref/customization.html):

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

comment:2 by jim-django@…, 18 years ago

Component: Core frameworkTemplate system
Type: enhancementdefect

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 Chris Beaven, 17 years ago

Resolution: invalid
Status: newclosed

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.

Note: See TracTickets for help on using tickets.
Back to Top