1
0
mirror of https://github.com/django/django.git synced 2024-12-22 17:16:24 +00:00

Fixed #32301 -- Made clearsessions raise CommandError when clear_expired() is not implemented.

This commit is contained in:
François Freitag 2020-05-18 22:11:46 +02:00 committed by Mariusz Felisiak
parent 270072c4c2
commit b11ec9a69e
3 changed files with 19 additions and 2 deletions

View File

@ -1,7 +1,7 @@
from importlib import import_module
from django.conf import settings
from django.core.management.base import BaseCommand
from django.core.management.base import BaseCommand, CommandError
class Command(BaseCommand):
@ -15,7 +15,7 @@ class Command(BaseCommand):
try:
engine.SessionStore.clear_expired()
except NotImplementedError:
self.stderr.write(
raise CommandError(
"Session engine '%s' doesn't support clearing expired "
"sessions." % settings.SESSION_ENGINE
)

View File

@ -0,0 +1,6 @@
from django.contrib.sessions.backends.base import SessionBase
class SessionStore(SessionBase):
"""Session store without support for clearing expired sessions."""
pass

View File

@ -910,3 +910,14 @@ class CookieSessionTests(SessionTestsMixin, SimpleTestCase):
@unittest.skip("CookieSession is stored in the client and there is no way to query it.")
def test_session_save_does_not_resurrect_session_logged_out_in_other_context(self):
pass
class ClearSessionsCommandTests(SimpleTestCase):
def test_clearsessions_unsupported(self):
msg = (
"Session engine 'tests.sessions_tests.no_clear_expired' doesn't "
"support clearing expired sessions."
)
with self.settings(SESSION_ENGINE='tests.sessions_tests.no_clear_expired'):
with self.assertRaisesMessage(management.CommandError, msg):
management.call_command('clearsessions')