1
0
mirror of https://github.com/django/django.git synced 2025-10-23 21:59:11 +00:00

Refs #29563 -- Fixed SQLCompiler.execute_sql() to respect DatabaseFeatures.can_use_chunked_reads.

This commit is contained in:
Andrew Brown
2018-07-20 14:54:14 -04:00
committed by Tim Graham
parent 4523beebb2
commit 55810d94d0
2 changed files with 16 additions and 2 deletions

View File

@@ -1,6 +1,7 @@
import datetime
from unittest import mock
from django.db import connections
from django.db.models.sql.compiler import cursor_iter
from django.test import TestCase
@@ -37,3 +38,15 @@ class QuerySetIteratorTests(TestCase):
self.assertEqual(cursor_iter_mock.call_count, 1)
mock_args, _mock_kwargs = cursor_iter_mock.call_args
self.assertEqual(mock_args[self.itersize_index_in_mock_args], batch_size)
def test_no_chunked_reads(self):
"""
If the database backend doesn't support chunked reads, then the
result of SQLCompiler.execute_sql() is a list.
"""
qs = Article.objects.all()
compiler = qs.query.get_compiler(using=qs.db)
features = connections[qs.db].features
with mock.patch.object(features, 'can_use_chunked_reads', False):
result = compiler.execute_sql(chunked_fetch=True)
self.assertIsInstance(result, list)