Fixed #32705 -- Prevented database cache backend from checking .rowcount on closed cursor.
Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com>
This commit is contained in:
parent
136ff592ad
commit
a0a5e0f4c8
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue