mirror of
				https://github.com/django/django.git
				synced 2025-10-31 01:25:32 +00:00 
			
		
		
		
	Fixed #32301 -- Made clearsessions raise CommandError when clear_expired() is not implemented.
This commit is contained in:
		
				
					committed by
					
						 Mariusz Felisiak
						Mariusz Felisiak
					
				
			
			
				
	
			
			
			
						parent
						
							270072c4c2
						
					
				
				
					commit
					b11ec9a69e
				
			| @@ -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 | ||||
|             ) | ||||
|   | ||||
							
								
								
									
										6
									
								
								tests/sessions_tests/no_clear_expired.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								tests/sessions_tests/no_clear_expired.py
									
									
									
									
									
										Normal 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 | ||||
| @@ -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') | ||||
|   | ||||
		Reference in New Issue
	
	Block a user