File tree Expand file tree Collapse file tree 2 files changed +9
-1
lines changed
django/core/cache/backends
tests/regressiontests/cache Expand file tree Collapse file tree 2 files changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -184,6 +184,7 @@ def clear(self):
184184 table = connections [db ].ops .quote_name (self ._table )
185185 cursor = connections [db ].cursor ()
186186 cursor .execute ('DELETE FROM %s' % table )
187+ transaction .commit_unless_managed (using = db )
187188
188189# For backwards compatibility
189190class CacheClass (DatabaseCache ):
Original file line number Diff line number Diff line change 1818from django .core .cache import get_cache
1919from django .core .cache .backends .base import (CacheKeyWarning ,
2020 InvalidCacheBackendError )
21- from django .db import router
21+ from django .db import router , transaction
2222from django .http import (HttpResponse , HttpRequest , StreamingHttpResponse ,
2323 QueryDict )
2424from django .middleware .cache import (FetchFromCacheMiddleware ,
@@ -836,6 +836,13 @@ def test_second_call_doesnt_crash(self):
836836 interactive = False
837837 )
838838
839+ def test_clear_commits_transaction (self ):
840+ # Ensure the database transaction is committed (#19896)
841+ self .cache .set ("key1" , "spam" )
842+ self .cache .clear ()
843+ transaction .rollback ()
844+ self .assertEqual (self .cache .get ("key1" ), None )
845+
839846
840847@override_settings (USE_TZ = True )
841848class DBCacheWithTimeZoneTests (DBCacheTests ):
You can’t perform that action at this time.
0 commit comments