Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#26504 closed Cleanup/optimization (fixed)

Prevent logging warnings for page "Not Found" before redirect to language-prefixed page

Reported by: cworth-gh Owned by: Tim Graham <timograham@…>
Component: Error reporting Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by cworth-gh)

I've noticed that I've been getting warnings logged for things like:

Not Found: /

This results from accessing a path of "/" which is getting redirected by LocaleMiddleware to "/en/". So, in fact there is never any actual "page not found" happening here, but the code is logging based on a temporary 404 exception that the LocaleMiddleware will touch up into a redirect response.

I admit that I'm a little OCD when it comes to my log files, and I prefer them to be warning-free when nothing wrong is happening.

I've got a commit series all ready to fix this bug, which I'll try to attach to this ticket in the appropriate way, (but please let me know if I get any of the details wrong).

The pull request is here:

https://github.com/django/django/pull/6453

Change History (4)

comment:1 by cworth-gh, 9 years ago

Description: modified (diff)

comment:2 by Tim Graham, 9 years ago

Summary: Warnings logged for page "Not Found" before redirect to language-prefixed pagePrevent logging warnings for page "Not Found" before redirect to language-prefixed page
Triage Stage: UnreviewedAccepted
Type: BugCleanup/optimization

comment:3 by Tim Graham <timograham@…>, 9 years ago

Owner: set to Tim Graham <timograham@…>
Resolution: fixed
Status: newclosed

In 40b69607:

Fixed #26504 -- Avoided logging "Not Found" warnings if a middleware handles the 404.

For example, this avoids a warning in the case of a request that's
redirected to a language-prefixed URL by LocaleMiddleware.

comment:4 by Samir Shah, 9 years ago

I just want to note that this change has altered the behaviour of Django's 404 logging somewhat.

Previously, Django would only log a 404 if a Http404 exception bubbled up to the core handler (and not if a view/middleware caught the exception and returned a response, regardless of whether that response was still a 404).

Now, it will log all 404 responses regardless of how they were generated. This seems better to me but there may be applications that were relying on the previous behaviour.

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