Opened 17 years ago

Closed 17 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: dev
Severity: Keywords:
Cc: 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

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 17 years ago.
patch against revision 6213

Download all attachments as: .zip

Change History (7)

comment:1 by Chris Beaven, 17 years ago

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 by Collin Grady <cgrady@…>, 17 years ago

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

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 by Grzegorz Ślusarek, 17 years ago

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

by Grzegorz Ślusarek, 17 years ago

patch against revision 6213

comment:4 by Grzegorz Ślusarek, 17 years ago

Has patch: set

comment:5 by Grzegorz Ślusarek, 17 years ago

Triage Stage: AcceptedReady for checkin

comment:6 by Malcolm Tredinnick, 17 years ago

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