1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Fixed #29339 -- Added result caching to RawQuerySet.

This commit is contained in:
Adnan Umer
2018-04-18 22:25:59 +05:00
committed by Tim Graham
parent c1c163b427
commit ec0319ff82
4 changed files with 25 additions and 4 deletions

View File

@@ -318,3 +318,15 @@ class RawQueryTests(TestCase):
c = Coffee.objects.create(brand='starbucks', price=20.5)
qs = Coffee.objects.raw("SELECT * FROM raw_query_coffee WHERE price >= %s", params=[Decimal(20)])
self.assertEqual(list(qs), [c])
def test_result_caching(self):
with self.assertNumQueries(1):
books = Book.objects.raw('SELECT * FROM raw_query_book')
list(books)
list(books)
def test_iterator(self):
with self.assertNumQueries(2):
books = Book.objects.raw('SELECT * FROM raw_query_book')
list(books.iterator())
list(books.iterator())