Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#17801 closed Bug (wontfix)

Adding DummyCache causes contrib.session tests to fail

Reported by: Dougal Matthews Owned by: nobody
Component: Core (Cache system) Version: 1.4-beta-1
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Tested against Django trunk this morning. Create a new project, set the database engine and add this to the settings;

CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
    },
}

Then run manage.py test and you should see this;

Creating test database for alias 'default'...
....................................................................................................................................F..........................F.....................................................................................................................................................................................................F......................................
======================================================================
FAIL: test_exists_searches_cache_first (django.contrib.sessions.tests.CacheDBSessionTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/vagrant/.virtualenvs/mgp/lib/python2.6/site-packages/django/contrib/sessions/tests.py", line 299, in test_exists_searches_cache_first
    self.assertTrue(self.session.exists(self.session.session_key))
  File "/home/vagrant/.virtualenvs/mgp/lib/python2.6/site-packages/django/test/testcases.py", line 274, in __exit__
    executed, self.num
AssertionError: 1 != 0 : 1 queries executed, 0 expected

======================================================================
FAIL: test_exists_searches_cache_first (django.contrib.sessions.tests.CacheDBSessionTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/vagrant/.virtualenvs/mgp/lib/python2.6/site-packages/django/contrib/sessions/tests.py", line 299, in test_exists_searches_cache_first
    self.assertTrue(self.session.exists(self.session.session_key))
  File "/home/vagrant/.virtualenvs/mgp/lib/python2.6/site-packages/django/test/testcases.py", line 274, in __exit__
    executed, self.num
AssertionError: 1 != 0 : 1 queries executed, 0 expected

======================================================================
FAIL: test_save (django.contrib.sessions.tests.CacheSessionTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/vagrant/.virtualenvs/mgp/lib/python2.6/site-packages/django/contrib/sessions/tests.py", line 136, in test_save
    self.assertTrue(self.session.exists(self.session.session_key))
AssertionError: False is not True

----------------------------------------------------------------------
Ran 396 tests in 15.930s

FAILED (failures=3)
Destroying test database for alias 'default'...

These make sense that they fail, but its not clear why from looking at the tracebacks. I guess the error should be clearer or they should be skipped?

Also, it seems strange, but one of the tests appears to have run and failed twice?

Change History (2)

comment:1 by Jannis Leidel, 13 years ago

Component: contrib.sessionsCore (Cache system)
Resolution: wontfix
Status: newclosed

This is an expected behavior since the dummy cache returns False by default when calling its has_key method (which is done by the cached_db and cache session backends' exists method) .

The workaround is to use the locmem cache backend instead.

comment:2 by Dougal Matthews, 13 years ago

while I agree this is the expected behaviour. Wouldn't it be a good idea to improve the test failure message? From the failed tests its not clear what the cause is.

I only bring this up, because I switched to an old experimental branch in a project, updated it to run against 1.4 and the tests started to fail - I had forgotten the DummyCache was still in the local settings, and thus I lost a bit of time finding the cause. So, it was useful that the errors let me know, but at the same time, it didn't tell me directly.

I'd propose changing the assert to something along the lines of;

self.assertTrue(self.session.exists(self.session.session_key), "The CachedDBSession failed to cache. Verify your CACHES setting is correct.")

Note: See TracTickets for help on using tickets.
Back to Top