Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#32637 closed Bug (fixed)

Technical 404 debug page doesn't display Http404's message in Django 3.2.

Reported by: Atul Varma Owned by: Mariusz Felisiak
Component: Error reporting Version: 3.2
Severity: Release blocker Keywords:
Cc: Jon Dufresne Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Hello! I'm currently upgrading a project from Django 2.2 to 3.2 (a bit sloppily, as I'm not incrementally upgrading to intermediate versions). I noticed that a few of my tests rely on the following behavior specified in the documentation for the Http404 exception:

When DEBUG is True, you can provide a message to Http404 and it will appear in the standard 404 debug template. Use these messages for debugging purposes; they generally aren’t suitable for use in a production 404 template.

I was able to test whether the message I passed was visible on the debug 404 page for the view (to make sure the page was 404'ing for the right reason). However, these tests have broken when upgrading to Django 3.2. Looking at the actual response content, it doesn't seem as though the actual message is visible anywhere on the page.

I'm currently just going to comment out the explicit test for finding the exception message, but I was curious if anyone else has found this kind of error as well, or if it's just me. If needed, I can try creating a simple test case that reproduces this error (though I'll admit the problem could be entirely on my end too).

Change History (6)

comment:1 by Mariusz Felisiak, 3 years ago

Cc: Jon Dufresne added
Component: UncategorizedError reporting
Severity: NormalRelease blocker
Summary: Http404 exception messages might not be propagating to 404 debug templates in Django 3.2Technical 404 debug page doesn't display Http404's message in Django 3.2.
Triage Stage: UnreviewedAccepted

Thanks for this report. Technical 404 debug page now always shows tried URL patterns, that's why Http404's message is no longer displayed. IMO we should keep showing a message, e.g.

diff --git a/django/views/templates/technical_404.html b/django/views/templates/technical_404.html
index 077bb20964..aeba2daf9c 100644
--- a/django/views/templates/technical_404.html
+++ b/django/views/templates/technical_404.html
@@ -20,11 +20,13 @@
     #info ol li { font-family: monospace; }
     #summary { background: #ffc; }
     #explanation { background:#eee; border-bottom: 0px none; }
+    pre.exception_value { font-family: sans-serif; color: #575757; font-size: 1.5em; margin: 10px 0 10px 0; }
   </style>
 </head>
 <body>
   <div id="summary">
     <h1>Page not found <span>(404)</span></h1>
+    {% if reason %}<pre class="exception_value">{{ reason }}</pre>{% endif %}
     <table class="meta">
       <tr>
         <th>Request Method:</th>
@@ -66,8 +68,6 @@
         {% endif %}
         {% if resolved %}matched the last one.{% else %}didn’t match any of these.{% endif %}
       </p>
-    {% else %}
-      <p>{{ reason }}</p>
     {% endif %}
   </div>

Regression in 11ebc6479ffda87376b60c9475d33d8120f86368.

comment:2 by Claude Paroz, 3 years ago

+1 for fixing that regression.

comment:3 by Mariusz Felisiak, 3 years ago

Owner: changed from nobody to Mariusz Felisiak
Status: newassigned

comment:4 by Mariusz Felisiak, 3 years ago

Has patch: set

comment:5 by GitHub <noreply@…>, 3 years ago

Resolution: fixed
Status: assignedclosed

In 3b8527e3:

Fixed #32637 -- Restored exception message on technical 404 debug page.

Thanks Atul Varma for the report.

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

In d6314c4:

[3.2.x] Fixed #32637 -- Restored exception message on technical 404 debug page.

Thanks Atul Varma for the report.
Backport of 3b8527e32b665df91622649550813bb1ec9a9251 from main

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