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

Refs #29984 -- Made QuerySet.iterator() without chunk_size raise ValueError after prefetch_related().

Per deprecation timeline.
This commit is contained in:
Mariusz Felisiak
2023-01-12 19:13:22 +01:00
parent b119f4329c
commit 1391356276
4 changed files with 11 additions and 36 deletions

View File

@@ -12,8 +12,7 @@ from django.test import (
skipIfDBFeature,
skipUnlessDBFeature,
)
from django.test.utils import CaptureQueriesContext, ignore_warnings
from django.utils.deprecation import RemovedInDjango50Warning
from django.test.utils import CaptureQueriesContext
from .models import (
Article,
@@ -385,25 +384,12 @@ class PrefetchRelatedTests(TestDataMixin, TestCase):
[self.author1, self.author1, self.author3, self.author4],
)
@ignore_warnings(category=RemovedInDjango50Warning)
def test_m2m_prefetching_iterator_without_chunks(self):
# prefetch_related() is ignored.
with self.assertNumQueries(5):
authors = [
b.authors.first()
for b in Book.objects.prefetch_related("authors").iterator()
]
self.assertEqual(
authors,
[self.author1, self.author1, self.author3, self.author4],
)
def test_m2m_prefetching_iterator_without_chunks_warning(self):
def test_m2m_prefetching_iterator_without_chunks_error(self):
msg = (
"Using QuerySet.iterator() after prefetch_related() without "
"specifying chunk_size is deprecated."
"chunk_size must be provided when using QuerySet.iterator() after "
"prefetch_related()."
)
with self.assertWarnsMessage(RemovedInDjango50Warning, msg):
with self.assertRaisesMessage(ValueError, msg):
Book.objects.prefetch_related("authors").iterator()