Django

Code

Ticket #4049 (closed: fixed)

Opened 1 year ago

Last modified 1 year ago

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

Reported by: David S. <dschein@fsinnovations.net> Assigned to: gregorth
Milestone: Component: Core framework
Version: SVN Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

AuthenticationMiddleware.diff (0.9 kB) - added by gregorth on 09/14/07 16:35:40.
patch against revision 6213

Change History

04/15/07 05:09:55 changed by SmileyChris

  • needs_better_patch changed.
  • stage changed from Unreviewed to Accepted.
  • summary changed from django.core.context_processors.auth should be in contrib to `auth` context processor shouldn't error if `AuthenticationMiddleware` isn't being used.
  • needs_tests changed.
  • needs_docs changed.

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)

04/24/07 22:53:47 changed by Collin Grady <cgrady@the-magi.us>

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.

09/14/07 09:33:56 changed by gregorth

  • owner changed from nobody to gregorth.
  • status changed from new to assigned.

09/14/07 16:35:40 changed by gregorth

  • attachment AuthenticationMiddleware.diff added.

patch against revision 6213

09/14/07 16:36:10 changed by gregorth

  • has_patch set to 1.

09/14/07 16:42:16 changed by gregorth

  • stage changed from Accepted to Ready for checkin.

09/16/07 06:27:40 changed by mtredinnick

  • status changed from assigned to closed.
  • resolution set to fixed.

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


Add/Change #4049 (`auth` context processor shouldn't error if `AuthenticationMiddleware` isn't being used)




Change Properties
Action