bug 564353, no more race conditions or any errors.

This commit is contained in:
Dave Dash 2010-05-07 17:17:27 -07:00
Родитель aef3c0c7c1
Коммит f472d1a5fe
2 изменённых файлов: 18 добавлений и 1 удалений

Просмотреть файл

@ -2,6 +2,7 @@ import logging
from time import time
from django.contrib.auth.models import User
from django.db import IntegrityError
import phpserialize
@ -55,7 +56,15 @@ class SessionBackend:
# Chances are we are suffering from replication lag, but
# let's play it safe and just not authenticate.
return None
except IntegrityError, e:
# Typically a duplicate key.
log.warning('DB Error for UserProfile {0}: {1}'.format(user_id, e))
return None
except Exception, e:
log.error('Unknown exception for UserProfile {0}: {1}'.format(
user_id, e))
return None
return profile.user

Просмотреть файл

@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from django.contrib.auth.models import AnonymousUser, User
from django.db import IntegrityError
from mock import Mock, patch
from nose.tools import eq_
@ -91,7 +92,7 @@ class CakeTestCase(TestCase):
@patch('django.db.models.fields.related.'
'ReverseSingleRelatedObjectDescriptor.__get__')
def test_bad_user_id(self, p_mock):
def test_backend_profile_exceptions(self, p_mock):
# We have a legitimate profile, but for some reason the user_id is phony
s = SessionBackend()
backend = SessionBackend()
@ -100,6 +101,13 @@ class CakeTestCase(TestCase):
p_mock.side_effect = User.DoesNotExist()
eq_(None, s.authenticate(session))
p_mock.side_effect = IntegrityError()
eq_(None, s.authenticate(session))
p_mock.side_effect = Exception()
eq_(None, s.authenticate(session))
class TestHelpers(TestCase):