Skip to content

Commit

Permalink
Fixed #19896 -- Committed after clearing cache in the database.
Browse files Browse the repository at this point in the history
  • Loading branch information
gsong authored and aaugustin committed Feb 24, 2013
1 parent b6aede3 commit 44164c5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions django/core/cache/backends/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ def clear(self):
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):
Expand Down
9 changes: 8 additions & 1 deletion tests/regressiontests/cache/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
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,
Expand Down Expand Up @@ -836,6 +836,13 @@ def test_second_call_doesnt_crash(self):
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):
Expand Down

0 comments on commit 44164c5

Please sign in to comment.