mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	Fixed #19896 -- Committed after clearing cache in the database.
This commit is contained in:
		
				
					committed by
					
						
						Aymeric Augustin
					
				
			
			
				
	
			
			
			
						parent
						
							b6aede3268
						
					
				
				
					commit
					44164c5c30
				
			
							
								
								
									
										1
									
								
								django/core/cache/backends/db.py
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								django/core/cache/backends/db.py
									
									
									
									
										vendored
									
									
								
							@@ -184,6 +184,7 @@ class DatabaseCache(BaseDatabaseCache):
 | 
			
		||||
        table = connections[db].ops.quote_name(self._table)
 | 
			
		||||
        cursor = connections[db].cursor()
 | 
			
		||||
        cursor.execute('DELETE FROM %s' % table)
 | 
			
		||||
        transaction.commit_unless_managed(using=db)
 | 
			
		||||
 | 
			
		||||
# For backwards compatibility
 | 
			
		||||
class CacheClass(DatabaseCache):
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										9
									
								
								tests/regressiontests/cache/tests.py
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										9
									
								
								tests/regressiontests/cache/tests.py
									
									
									
									
										vendored
									
									
								
							@@ -18,7 +18,7 @@ from django.core import management
 | 
			
		||||
from django.core.cache import get_cache
 | 
			
		||||
from django.core.cache.backends.base import (CacheKeyWarning,
 | 
			
		||||
    InvalidCacheBackendError)
 | 
			
		||||
from django.db import router
 | 
			
		||||
from django.db import router, transaction
 | 
			
		||||
from django.http import (HttpResponse, HttpRequest, StreamingHttpResponse,
 | 
			
		||||
    QueryDict)
 | 
			
		||||
from django.middleware.cache import (FetchFromCacheMiddleware,
 | 
			
		||||
@@ -836,6 +836,13 @@ class DBCacheTests(BaseCacheTests, TransactionTestCase):
 | 
			
		||||
                interactive=False
 | 
			
		||||
            )
 | 
			
		||||
 | 
			
		||||
    def test_clear_commits_transaction(self):
 | 
			
		||||
        # Ensure the database transaction is committed (#19896)
 | 
			
		||||
        self.cache.set("key1", "spam")
 | 
			
		||||
        self.cache.clear()
 | 
			
		||||
        transaction.rollback()
 | 
			
		||||
        self.assertEqual(self.cache.get("key1"), None)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@override_settings(USE_TZ=True)
 | 
			
		||||
class DBCacheWithTimeZoneTests(DBCacheTests):
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user