better error handling in templatetags?

11 views
Skip to first unread message

pihentagy

unread,
Nov 11, 2009, 5:13:42 AM11/11/09
to Django users
Hi all!

I am not satisfied with the error handling inside custom template
tags.
To demonstrate it, I cooked a mini useless app, which can be
downloaded here:

What I miss from the error screen is the actual location of the error.

http://cid-a93120a1b42a9e7f.skydrive.live.com/self.aspx/.Public/djangotest.zip

Or did I do something wrong, that I miss the error message?

pihentagy

unread,
Nov 26, 2009, 9:09:49 AM11/26/09
to Django users
Isn't it a known thing, that template tags are hard to debug? Did I
miss something?

On Nov 11, 11:13 am, pihentagy <pihent...@gmail.com> wrote:
> Hi all!
>
> I am not satisfied with the error handling inside custom template
> tags.
> To demonstrate it, I cooked a mini useless app, which can be
> downloaded here:
>
> What I miss from the error screen is the actual location of the error.
>
> http://cid-a93120a1b42a9e7f.skydrive.live.com/self.aspx/.Public/djang...

Karen Tracey

unread,
Nov 26, 2009, 11:35:17 AM11/26/09
to django...@googlegroups.com
On Thu, Nov 26, 2009 at 9:09 AM, pihentagy <pihe...@gmail.com> wrote:
Isn't it a known thing, that template tags are hard to debug? Did I
miss something?

I don't know, but your original message makes it a little too hard to try to help probably.  You say the actual location of the error is missing, but in order to see what you are seeing people have to download a zip file from somewhere and go to some trouble to unzip and install and figure out what to run to recreate the problem, etc.  Why not just post the traceback you are getting, along with whatever snippets of the associated code that are relevant? You might get better feedback from that.

Karen
 
 
On Nov 11, 11:13 am, pihentagy <pihent...@gmail.com> wrote:
> Hi all!
>
> I am not satisfied with the error handling inside custom template
> tags.
> To demonstrate it, I cooked a mini useless app, which can be
> downloaded here:
>
> What I miss from the error screen is the actual location of the error.
>
> http://cid-a93120a1b42a9e7f.skydrive.live.com/self.aspx/.Public/djang...
>
> Or did I do something wrong, that I miss the error message?

--

You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.



KONTRA, Gergely

unread,
Nov 26, 2009, 6:02:47 PM11/26/09
to django...@googlegroups.com
My problem is the error handling of django in templatetags, not the
specific dummy error, which I programmed:

@register.simple_tag
def current_time():
1/0
return unicode(datetime.datetime.now())

What annoys me, that you cannot find the line number of the error,
just a message, that somewhere there is an error rendering the
current_time tag.

+-[ Gergely Kontra <pihe...@gmail.com> ]------------------+
|                                                           |
| Mobile:(+36 20)356 9656                                   |
|                                                           |
+- "Olyan lángész vagyok, hogy poroltóval kellene járnom!" -+

Karen Tracey

unread,
Nov 26, 2009, 10:38:51 PM11/26/09
to django...@googlegroups.com
On Thu, Nov 26, 2009 at 6:02 PM, KONTRA, Gergely <pihe...@gmail.com> wrote:
My problem is the error handling of django in templatetags, not the
specific dummy error, which I programmed:

@register.simple_tag
def current_time():
       1/0
       return unicode(datetime.datetime.now())

What annoys me, that you cannot find the line number of the error,
just a message, that somewhere there is an error rendering the
current_time tag.


With DEBUG=True, TEMPLATE_DEBUG=DEBUG, I get a TemplateSyntaxError debug page with exception value:

Caught an exception while rendering: integer division or modulo by zero

Original Traceback (most recent call last):
  File "d:\u\kmt\django\trunk\django\template\debug.py", line 71, in render_node
    result = node.render(context)
  File "d:\u\kmt\django\trunk\django\template\__init__.py", line 909, in render
    return func(*resolved_vars)
  File "D:\u\kmt\software\web\playground\ttt\templatetags\tstuff.py", line 6, in current_time
    1/0
ZeroDivisionError: integer division or modulo by zero

So I am seeing the line number of the error reported.  It's (somewhat annoyingly) not actually in the traceback portion of the page, but it is on the page.  Are you seeing something different?

Karen

KONTRA, Gergely

unread,
Nov 27, 2009, 5:58:19 AM11/27/09
to django...@googlegroups.com
Seems like you built your own project, and not using my zip.

However, the result IS different.

In my traceback I do not have any snippet referencing customtag.py.

See my trace: http://dpaste.com/hold/125819/

thanks
Gergo
+-[ Gergely Kontra <pihe...@gmail.com> ]------------------+
|                                                           |
| Mobile:(+36 20)356 9656                                   |
|                                                           |
+- "Olyan lángész vagyok, hogy poroltóval kellene járnom!" -+



Tim Valenta

unread,
Nov 27, 2009, 10:27:39 AM11/27/09
to Django users
Django is forced to catch your errors, and then bubble them back up to
you. If you notice, none of the traceback lines are even in your
code-- it's all in Python libs or an Django code. The issue is that
you're not seeing raw exceptions, but instead you're seeing reproduced
exceptions.

I agree that template tags are had to debug, especially when it's a
big complex tag that goes wrong all of the sudden. However, don't
forget that it's just a Python object or method, just why not fire up
the shell and import it, testing it out? Step through it with input
that you *know* you're getting, and use the Django modules to create
dummy contexts if needed (although you could probably get away with
just Python dict objects, since the template rendering engine won't
actually be involved).

Fixing the reporting would be amazingly welcome by many of us, but
it's not like it's a simple matter of printing a single debug variable
that accidentally got omitted. I don't know enough about how Django
bubbles exceptions, so I can't say much more on the subject, but it's
clear to me that it's not something that they're doing on purpose to
spit us all.

Tim

On Nov 27, 3:58 am, "KONTRA, Gergely" <pihent...@gmail.com> wrote:
> Seems like you built your own project, and not using my zip.
>
> However, the result IS different.
>
> In my traceback I do not have any snippet referencing customtag.py.
>
> See my trace:http://dpaste.com/hold/125819/
>
> thanks
> Gergo
> +-[ Gergely Kontra <pihent...@gmail.com> ]------------------+
> |                                                           |
> | Mobile:(+36 20)356 9656                                   |
> |                                                           |
> +- "Olyan lángész vagyok, hogy poroltóval kellene járnom!" -+
>
>
>
> On Fri, Nov 27, 2009 at 04:38, Karen Tracey <kmtra...@gmail.com> wrote:
> > On Thu, Nov 26, 2009 at 6:02 PM, KONTRA, Gergely <pihent...@gmail.com>

Tim Valenta

unread,
Nov 27, 2009, 10:28:52 AM11/27/09
to Django users
spite* us all.

Sorry :)

Karen Tracey

unread,
Nov 27, 2009, 11:22:24 AM11/27/09
to django...@googlegroups.com
On Fri, Nov 27, 2009 at 5:58 AM, KONTRA, Gergely <pihe...@gmail.com> wrote:
Seems like you built your own project, and not using my zip.

Yes, because just cut and pasting the template tag into my existing working test project seemed easier than downloading a zip file.  But even after retrieving the zip file and working from that (I had to remove the references to admin in the urls.py file since admin isn't in the INSTALLED_APPS setting) I still see the original traceback reflected in the message, so the difference between what you and I see is not due to differences in the projects.
 
  
However, the result IS different.

In my traceback I do not have any snippet referencing customtag.py.

See my trace: http://dpaste.com/hold/125819/

Hmm.  Your traceback shows you are using Python 2.6.  If I switch to that, then I see the behavior you are describing.  For some reason under Python 2.6 the exception value is being truncated at the end of the first line, so the original traceback is getting lost. 

There is a ticket open on the whole exception wrapping behavior of handing exceptions that occur during template rendering:

http://code.djangoproject.com/ticket/11461

I have not looked in detail at how things behave with the proposed patches, partly because since I've been seeing the original exception the wrapping behavior did not strike me as quite that bad.  Perhaps you can try out the patches, see if they improve things for your environment, and give some feedback.

Karen

KONTRA, Gergely

unread,
Nov 27, 2009, 4:14:10 PM11/27/09
to django...@googlegroups.com
Thanks. With a one-line patch now I can debug templatetags :)))

Oh dear, target milestone is 1.2 I don't know why is it so slow.

Gergo
+-[ Gergely Kontra <pihe...@gmail.com> ]------------------+
|                                                           |
| Mobile:(+36 20)356 9656                                   |
|                                                           |
+- "Olyan lángész vagyok, hogy poroltóval kellene járnom!" -+



Reply all
Reply to author
Forward
0 new messages