Opened 19 years ago
Closed 18 years ago
#4049 closed (fixed)
`auth` context processor shouldn't error if `AuthenticationMiddleware` isn't being used
| Reported by: | 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)
Change History (7)
comment:1 by , 19 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: | Unreviewed → Accepted |
comment:2 by , 19 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 , 18 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
comment:4 by , 18 years ago
| Has patch: | set |
|---|
comment:5 by , 18 years ago
| Triage Stage: | Accepted → Ready for checkin |
|---|
comment:6 by , 18 years ago
| Resolution: | → fixed |
|---|---|
| Status: | assigned → closed |
It seems there are two facets to this ticket:
django.core.context_processors.authshould be incontribauthfails ifAuthenticationMiddlewareisn't being usedThey 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)