﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
15026	Test failures in django.contrib.sessions on default project when memcached used as CACHE_BACKEND	Jim Dalton	nobody	"When running the `test` management command on a basic, default project, with django.contrib.sessions as the only app in INSTALLED_APPS, and memcached as the CACHE_BACKEND I'm getting the following test failures:

{{{
FAIL: test_invalid_key (django.contrib.sessions.tests.CacheDBSessionTests)
FAIL: test_invalid_key (django.contrib.sessions.tests.CacheSessionTests)
}}}

The tests run fine (no failures) the first time they are run after memcached is restarted. The next time the tests are run, however, the failures occur.

Here's a more detailed rundown:

{{{
# settings.py

...

INSTALLED_APPS = (
    #'django.contrib.contenttypes',
    #'django.contrib.auth',
    'django.contrib.sessions',
    #'django.contrib.sites',
    #'django.contrib.messages',
    #'django.contrib.staticfiles',
    # Uncomment the next line to enable the admin:
    # 'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    # 'django.contrib.admindocs',
)

...

CACHE_BACKEND = 'memcached://127.0.0.1:11211/'
}}}

{{{
# first,  make sure to restart memcached
$ ./manage.py test
Creating test database for alias 'default'...
.....................................................................................................
----------------------------------------------------------------------
Ran 101 tests in 0.188s

OK
Destroying test database for alias 'default'...

# now run the tests another time
$ ./manage.py test
Creating test database for alias 'default'...
.............F.................................................F.....................................
======================================================================
FAIL: test_invalid_key (django.contrib.sessions.tests.CacheDBSessionTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File ""/Users/jsdalton/webs/testproject/src/django/django/contrib/sessions/tests.py"", line 165, in test_invalid_key
    self.assertNotEqual(session.session_key, '1')
AssertionError: '1' == '1'

======================================================================
FAIL: test_invalid_key (django.contrib.sessions.tests.CacheSessionTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File ""/Users/jsdalton/webs/testproject/src/django/django/contrib/sessions/tests.py"", line 165, in test_invalid_key
    self.assertNotEqual(session.session_key, '1')
AssertionError: '1' == '1'

----------------------------------------------------------------------
Ran 101 tests in 0.159s

FAILED (failures=2)
Destroying test database for alias 'default'...
}}}

I have not yet investigated the possible causes for this bug, though it appears as though the cache is perhaps not being flushed appropriately during some portion of the testing and thus values are hanging around in the cache when the test is run next. If I have a chance later, I'll take a closer look.
"		closed	contrib.sessions	dev		fixed			Accepted	1	0	0	1	0	0
