Opened 10 years ago

Closed 9 years ago

#4049 closed (fixed)

`auth` context processor shouldn't error if `AuthenticationMiddleware` isn't being used

Reported by: David S. <dschein@…> Owned by: Grzegorz Ślusarek
Component: Core (Other) Version: master
Severity: Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


TEMPLATE_CONTEXT_PROCESSORS default includes django.core.context_processors.auth. This callable assumes that something (presumably django.contrib.auth.middleware.AuthenticationMiddleware) has added an attribute, 'user', to the request. So django.core.context_processors.auth throws an AttributeError exception.

It seems this should be better documented or maybe just wrap the return in the auth method with a try and return {} if there is an AttributeException. Anyway, most everyone must use auth!

Attachments (1)

AuthenticationMiddleware.diff (910 bytes) - added by Grzegorz Ślusarek 9 years ago.
patch against revision 6213

Download all attachments as: .zip

Change History (7)

comment:1 Changed 10 years ago by Chris Beaven

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
Summary: django.core.context_processors.auth should be in contrib`auth` context processor shouldn't error if `AuthenticationMiddleware` isn't being used
Triage Stage: UnreviewedAccepted

It seems there are two facets to this ticket:

  1. django.core.context_processors.auth should be in contrib
  2. context processor auth fails if AuthenticationMiddleware isn't being used

They seem two independent issues, so I'm going to rename the title of this one to issue 2 which seems the more pressing. Thanks for the report David, and feel free to open another ticket just focussing on moving the processor to auth (which would be a hard sell with it breaking backwards compatibility with every default project ever created)

comment:2 Changed 10 years ago by Collin Grady <cgrady@…>

Projects created from startproject do not define TEMPLATE_CONTEXT_PROCESSORS though, so they're all using the default value from

If the processor was moved and the default TEMPLATE_CONTEXT_PROCESSORS value adjusted, they'd all work just fine - only those who redefined the value will have to update their settings.

comment:3 Changed 9 years ago by Grzegorz Ślusarek

Owner: changed from nobody to Grzegorz Ślusarek
Status: newassigned

Changed 9 years ago by Grzegorz Ślusarek

patch against revision 6213

comment:4 Changed 9 years ago by Grzegorz Ślusarek

Has patch: set

comment:5 Changed 9 years ago by Grzegorz Ślusarek

Triage Stage: AcceptedReady for checkin

comment:6 Changed 9 years ago by Malcolm Tredinnick

Resolution: fixed
Status: assignedclosed

(In [6356]) Fixed #4049 -- Improved error handling in auth() context processor. Based on a patch from gregorth.

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