Code

Opened 8 years ago

Closed 8 years ago

#845 closed defect (fixed)

flatpages middleware throws 404 exception instead of returning response

Reported by: hugo Owned by: adrian
Component: Core (Other) Version:
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

The new middleware for flatpages athrows an exception when a flatpage is not there, instead just returning the 404 response. That leads to weird tracebacks with DEBUG=True, instead of the expected nice formatted 404 page. A fix (against new_admin, but should be identical in trunk):

Index: contrib/flatpages/middleware.py
===================================================================
--- contrib/flatpages/middleware.py     (revision 1289)
+++ contrib/flatpages/middleware.py     (working copy)
@@ -1,5 +1,6 @@
 from django.contrib.flatpages.views import flatpage
 from django.conf.settings import DEBUG
+from django.core.extensions import Http404
 
 class FlatpageFallbackMiddleware:
     def process_response(self, request, response):
@@ -9,6 +10,8 @@
             return flatpage(request, request.path)
         # Return the original response if any errors happened. Because this
         # is a middleware, we can't assume the errors will be caught elsewhere.
+        except Http404:
+            return response
         except:
             if DEBUG:
                 raise

The redirects middleware seems already to check for this situation. Actually the flatpages middleware does talk in a comment about exactly this problem, but just doesn't implement it ;-)

BTW: maybe a component "contributed apps" would be in order, since flatpages and redirects aren't part of core any more?

Attachments (0)

Change History (1)

comment:1 Changed 8 years ago by adrian

  • Resolution set to fixed
  • Status changed from new to closed

(In [1296]) Fixed #845 -- flatpages middleware no longer throws 404 exception for DEBUG=True. Thanks, Hugo

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.