Opened 3 years ago

Closed 3 years ago

#33396 closed New feature (fixed)

Add the ResolverMatch's name to the technical 500 page.

Reported by: Keryn Knight Owned by: Hrushikesh Vaidya
Component: Error reporting Version: dev
Severity: Normal Keywords:
Cc: Hrushikesh Vaidya Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Way back when in #22756, I asked for and was given a lovely addition to the technical 404 page, so that when raise Http404('...') was used it would report the view being executed, so that coming back to a project and getting an error would give me a hint where to look.

It looks like this, give or take alignment:

Request Method:	GET
Request URL:	http://localhost:8080/egsdh
Raised by:	__main__.ItemDetail

Today I'm here to ask for the same in the technical 500 page.
I just opened a project from about 3 weeks ago and in that short time had apparently forgotten what views were mounted on what URLs, and however many years after that ticket, Django still doesn't have a management command for printing me the URLs (... sigh), so I had to go digging again to deal with the error I'd evidently left myself.

django.views.debug.ExceptionReporter.get_traceback_data already has awareness of the request (if self.request is not None) which it uses to print the GET/POST/etc. I'd like to suggest that within that block, we do something like:

if self.request is not None:
    try:
        view_name = self.request.resolver_match._func_path
    except Exception:
        view_name = None
    c['view_name'] = view_name

and then adjust the template to have a Raised by: {{ view_name }} line as the technical 404 page, guarding it with an {% if %} test. We might want to change the label from Raised by across both to something like Raised during or During View or something ...

The 500 page might thus look something like:

Request Method:	GET
Request URL:	http://localhost:8080/
View name:	__main__.ItemList
Django Version:	4.x.x
Exception Type:	ZeroDivisionError
Exception Value:division by zero
...

By the look of it, the code for the technical 404 page and the ResolverMatch name may mostly overlap in terms of calculation/output, except:

  • #32260 was relatively recently patched into the 404 page, so that references .view_class
  • ResolverMatch is separately aware that the func might be a functools.partial, but only within the __repr__

So it's possible there could be some tidying up/DRY aside from those edges.

Change History (9)

comment:1 by Mariusz Felisiak, 3 years ago

Triage Stage: UnreviewedAccepted

Sounds reasonable.

comment:2 by Keryn Knight, 3 years ago

Owner: set to Keryn Knight
Status: newassigned

comment:3 by Hrushikesh Vaidya, 3 years ago

Cc: Hrushikesh Vaidya added

comment:4 by Hrushikesh Vaidya, 3 years ago

I have a quick PR for an initial patch that addresses the feature, except the DRYing up of the technical 404 and ResolverMatch.

comment:5 by Mariusz Felisiak, 3 years ago

Has patch: set
Needs tests: set
Owner: changed from Keryn Knight to Hrushikesh Vaidya
Patch needs improvement: set

I hope you don't mind Keryn.

comment:6 by Hrushikesh Vaidya, 3 years ago

Needs tests: unset
Patch needs improvement: unset

comment:7 by Mariusz Felisiak, 3 years ago

Triage Stage: AcceptedReady for checkin

comment:8 by Mariusz Felisiak <felisiak.mariusz@…>, 3 years ago

In 4099e6e7:

Refs #33396 -- Added django.views.debug.get_caller() hook.

comment:9 by Mariusz Felisiak <felisiak.mariusz@…>, 3 years ago

Resolution: fixed
Status: assignedclosed

In 6815da6e:

Fixed #33396 -- Added view name to technical 500 debug page.

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