Fixed #2770 -- Fixed a database connection leak in

django.contrib.auth.handlers.modpython.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@3789 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Malcolm Tredinnick 2006-09-22 12:01:15 +00:00
parent 14be60c4cb
commit 9e05fc1598
1 changed files with 18 additions and 13 deletions

View File

@ -22,6 +22,8 @@ def authenhandler(req, **kwargs):
os.environ['DJANGO_SETTINGS_MODULE'] = settings_module os.environ['DJANGO_SETTINGS_MODULE'] = settings_module
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django import db
db.reset_queries()
# check that the username is valid # check that the username is valid
kwargs = {'username': req.user, 'is_active': True} kwargs = {'username': req.user, 'is_active': True}
@ -29,6 +31,7 @@ def authenhandler(req, **kwargs):
kwargs['is_staff'] = True kwargs['is_staff'] = True
if superuser_only: if superuser_only:
kwargs['is_superuser'] = True kwargs['is_superuser'] = True
try:
try: try:
user = User.objects.get(**kwargs) user = User.objects.get(**kwargs)
except User.DoesNotExist: except User.DoesNotExist:
@ -45,3 +48,5 @@ def authenhandler(req, **kwargs):
return apache.OK return apache.OK
else: else:
return apache.HTTP_UNAUTHORIZED return apache.HTTP_UNAUTHORIZED
finally:
db.connection.close()