summaryrefslogtreecommitdiff
path: root/tests/cache
diff options
context:
space:
mode:
authorecogels <ecogels@users.noreply.github.com>2021-05-02 10:42:23 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2021-05-05 12:41:59 +0200
commita0a5e0f4c83acdfc6eab69754e245354689c7185 (patch)
tree44f749fa0e9d08e20b2ac69aa86107ae01eb779f /tests/cache
parent136ff592ad8aa8b7fa1e61435e5501cc98ce8573 (diff)
downloaddjango-a0a5e0f4c83acdfc6eab69754e245354689c7185.tar.gz
Fixed #32705 -- Prevented database cache backend from checking .rowcount on closed cursor.
Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com>
Diffstat (limited to 'tests/cache')
-rw-r--r--tests/cache/tests.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/cache/tests.py b/tests/cache/tests.py
index 9d79e6e758..c189e26e70 100644
--- a/tests/cache/tests.py
+++ b/tests/cache/tests.py
@@ -24,6 +24,7 @@ from django.core.cache import (
from django.core.cache.backends.base import InvalidCacheBackendError
from django.core.cache.utils import make_template_fragment_key
from django.db import close_old_connections, connection, connections
+from django.db.backends.utils import CursorWrapper
from django.http import (
HttpRequest, HttpResponse, HttpResponseNotModified, StreamingHttpResponse,
)
@@ -1116,6 +1117,27 @@ class DBCacheTests(BaseCacheTests, TransactionTestCase):
with self.assertNumQueries(1):
cache.delete_many(['a', 'b', 'c'])
+ def test_delete_cursor_rowcount(self):
+ """
+ The rowcount attribute should not be checked on a closed cursor.
+ """
+ class MockedCursorWrapper(CursorWrapper):
+ is_closed = False
+
+ def close(self):
+ self.cursor.close()
+ self.is_closed = True
+
+ @property
+ def rowcount(self):
+ if self.is_closed:
+ raise Exception('Cursor is closed.')
+ return self.cursor.rowcount
+
+ cache.set_many({'a': 1, 'b': 2})
+ with mock.patch('django.db.backends.utils.CursorWrapper', MockedCursorWrapper):
+ self.assertIs(cache.delete('a'), True)
+
def test_zero_cull(self):
self._perform_cull_test('zero_cull', 50, 18)