Opened 4 months ago

Closed 4 months ago

Last modified 4 months ago

#32997 closed Bug (wontfix)

Errors in 404 templates are hard to debug

Reported by: jooadam Owned by:
Component: Error reporting Version: 3.2
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by jooadam)

I have a custom 404.html template, which extends a fairly complex base template. Something in this base template raises an error when visiting a non-existing page, but in DEBUG=True the page never gets rendered, and in DEBUG=False I only see the 500 error page and the email sent to the ADMINS address, which does not include a stack trace, or rather, has None listed under the stack trace.

I have no idea how to proceed with debugging, short of removing and adding back every single dynamic statement and expression in my base template.

Attachments (1)

404-error.zip (2.0 KB) - added by jooadam 4 months ago.

Download all attachments as: .zip

Change History (8)

comment:1 Changed 4 months ago by jooadam

Description: modified (diff)

comment:2 Changed 4 months ago by Mariusz Felisiak

Resolution: invalid
Status: newclosed

It looks like you're asking for help with debugging. Trac is not a support channel. Please see TicketClosingReasons/UseSupportChannels for ways to get help.

comment:3 in reply to:  2 ; Changed 4 months ago by jooadam

Replying to Mariusz Felisiak:

It looks like you're asking for help with debugging. Trac is not a support channel. Please see TicketClosingReasons/UseSupportChannels for ways to get help.

Mariusz, can you please explain to me how is an error in a template resulting in an 500 error not having a stack trace included in the email report not a bug? I have already found the issue in my code, so at this point I’m solely trying to make Django better by making the effort reporting it. I would expect you to take it a little more seriously.

comment:4 in reply to:  3 ; Changed 4 months ago by Mariusz Felisiak

Mariusz, can you please explain to me how is an error in a template resulting in an 500 error not having a stack trace included in the email report not a bug?

I cannot because you have not explained the issue in enough detail to confirm a bug in Django. Please reopen the ticket if you can debug your issue and provide details about why and where Django is at fault.

Changed 4 months ago by jooadam

Attachment: 404-error.zip added

comment:5 in reply to:  4 Changed 4 months ago by jooadam

Replying to Mariusz Felisiak:

I cannot because you have not explained the issue in enough detail to confirm a bug in Django. Please reopen the ticket if you can debug your issue and provide details about why and where Django is at fault.

I explained the issue in the exact detail you would have needed to reproduce it: a 404.html with an error in production mode. See the attachment.

comment:6 Changed 4 months ago by jooadam

Resolution: invalid
Status: closednew

comment:7 Changed 4 months ago by Carlton Gibson

Resolution: wontfix
Status: newclosed

Hi. Thanks for the extra info.

I have a custom 404.html template...

So custom error templates should (in general) be entirely straight-forward, in order to be certain not to raise an error themselves.
(Adding complexity to the default error handlers here isn't something we want to get into.)

In your case, where you want a more complex template, it's incumbent upon you to also customise the error views to ensure any possible exceptions are appropriately dealt with.

Minimally, you could add logging if you introduce the possibility of an exception:

import logging

from django.views.defaults import page_not_found


logger = logging.getLogger(__name__)


def custom_page_not_found(request, exception, template_name='404.html'):
    try:
        return page_not_found(request, exception, template_name)
    except:
        logger.exception("ERROR OCCURRED")
        raise


handler404 = 'foo.urls.custom_page_not_found'

Your traceback is then available.

See also the Testing custom error views section, that will enable you to make sure your error handling works before putting it live.

Last edited 4 months ago by jooadam (previous) (diff)
Note: See TracTickets for help on using tickets.
Back to Top