summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorFrançois Freitag <mail@franek.fr>2017-04-18 11:15:42 -0700
committerClaude Paroz <claude@2xlibre.net>2017-04-20 17:43:39 +0200
commit56746fb21f6bbf93fe96f4e3908040111439c9c3 (patch)
tree9bc008d23c692b1d86939bc1517774301f0de707 /tests
parent5e2bbcd70c9b0213bfda31b90e4b1c35815880e9 (diff)
[1.11.x] Fixed #28091 -- Re-raised original exception when closing cursor cleanup fails
Diffstat (limited to 'tests')
-rw-r--r--tests/backends/tests.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/backends/tests.py b/tests/backends/tests.py
index 9b31356bfe..5a49d99217 100644
--- a/tests/backends/tests.py
+++ b/tests/backends/tests.py
@@ -682,6 +682,25 @@ class BackendTestCase(TransactionTestCase):
self.create_squares(args, 'pyformat', multiple=True)
self.assertEqual(Square.objects.count(), 9)
+ def test_cursor_close_failure_does_not_mask_original_exception(self):
+ persons = Person.objects.iterator()
+
+ def raise_original_exception(*args, **kwargs):
+ raise Exception('Real exception raised by the database on cursor.execute')
+
+ def raise_close_exception():
+ raise Exception(
+ 'Error when attempting to close the cursor, this exception should not mask the original exception'
+ )
+
+ mock_cursor = connection.chunked_cursor()
+ mock_cursor.execute = mock.MagicMock(side_effect=raise_original_exception)
+ mock_cursor.close = mock.MagicMock(side_effect=raise_close_exception)
+
+ with self.assertRaisesMessage(Exception, 'Real exception raised by the database on cursor.execute'):
+ with mock.patch('django.db.connection.create_cursor', return_value=mock_cursor):
+ list(persons)
+
def test_unicode_fetches(self):
# fetchone, fetchmany, fetchall return strings as unicode objects #6254
qn = connection.ops.quote_name