Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
  • Loading branch information...
commit 9e05fc1598a676246bfbbd4113a5bcf9d3796642 1 parent 14be60c
Malcolm Tredinnick authored September 22, 2006

Showing 1 changed file with 18 additions and 13 deletions. Show diff stats Hide diff stats

  1. 31  django/contrib/auth/handlers/modpython.py
31  django/contrib/auth/handlers/modpython.py
@@ -22,6 +22,8 @@ def authenhandler(req, **kwargs):
22 22
         os.environ['DJANGO_SETTINGS_MODULE'] = settings_module
23 23
 
24 24
     from django.contrib.auth.models import User
  25
+    from django import db
  26
+    db.reset_queries()
25 27
 
26 28
     # check that the username is valid
27 29
     kwargs = {'username': req.user, 'is_active': True}
@@ -30,18 +32,21 @@ def authenhandler(req, **kwargs):
30 32
     if superuser_only:
31 33
         kwargs['is_superuser'] = True
32 34
     try:
33  
-        user = User.objects.get(**kwargs)
34  
-    except User.DoesNotExist:
35  
-        return apache.HTTP_UNAUTHORIZED
36  
-
37  
-    # check the password and any permission given
38  
-    if user.check_password(req.get_basic_auth_pw()):
39  
-        if permission_name:
40  
-            if user.has_perm(permission_name):
41  
-                return apache.OK
  35
+        try:
  36
+            user = User.objects.get(**kwargs)
  37
+        except User.DoesNotExist:
  38
+            return apache.HTTP_UNAUTHORIZED
  39
+    
  40
+        # check the password and any permission given
  41
+        if user.check_password(req.get_basic_auth_pw()):
  42
+            if permission_name:
  43
+                if user.has_perm(permission_name):
  44
+                    return apache.OK
  45
+                else:
  46
+                    return apache.HTTP_UNAUTHORIZED
42 47
             else:
43  
-                return apache.HTTP_UNAUTHORIZED
  48
+                return apache.OK
44 49
         else:
45  
-            return apache.OK
46  
-    else:
47  
-        return apache.HTTP_UNAUTHORIZED
  50
+            return apache.HTTP_UNAUTHORIZED
  51
+    finally:
  52
+        db.connection.close()

0 notes on commit 9e05fc1

Please sign in to comment.
Something went wrong with that request. Please try again.