mirror of
https://github.com/django/django.git
synced 2025-06-05 03:29:12 +00:00
Refs #29984 -- Made QuerySet.iterator() without chunk_size raise ValueError after prefetch_related().
Per deprecation timeline.
This commit is contained in:
parent
5a0e5d5cf0
commit
2e4d188e7c
@ -33,7 +33,6 @@ from django.db.models.utils import (
|
|||||||
resolve_callables,
|
resolve_callables,
|
||||||
)
|
)
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.utils.deprecation import RemovedInDjango50Warning
|
|
||||||
from django.utils.functional import cached_property, partition
|
from django.utils.functional import cached_property, partition
|
||||||
|
|
||||||
# The maximum number of results to fetch in a get() query.
|
# The maximum number of results to fetch in a get() query.
|
||||||
@ -529,16 +528,9 @@ class QuerySet(AltersData):
|
|||||||
"""
|
"""
|
||||||
if chunk_size is None:
|
if chunk_size is None:
|
||||||
if self._prefetch_related_lookups:
|
if self._prefetch_related_lookups:
|
||||||
# When the deprecation ends, replace with:
|
raise ValueError(
|
||||||
# raise ValueError(
|
"chunk_size must be provided when using QuerySet.iterator() after "
|
||||||
# 'chunk_size must be provided when using '
|
"prefetch_related()."
|
||||||
# 'QuerySet.iterator() after prefetch_related().'
|
|
||||||
# )
|
|
||||||
warnings.warn(
|
|
||||||
"Using QuerySet.iterator() after prefetch_related() "
|
|
||||||
"without specifying chunk_size is deprecated.",
|
|
||||||
category=RemovedInDjango50Warning,
|
|
||||||
stacklevel=2,
|
|
||||||
)
|
)
|
||||||
elif chunk_size <= 0:
|
elif chunk_size <= 0:
|
||||||
raise ValueError("Chunk size must be strictly positive.")
|
raise ValueError("Chunk size must be strictly positive.")
|
||||||
|
@ -2476,12 +2476,6 @@ value for ``chunk_size`` will result in Django using an implicit default of
|
|||||||
Depending on the database backend, query results will either be loaded all at
|
Depending on the database backend, query results will either be loaded all at
|
||||||
once or streamed from the database using server-side cursors.
|
once or streamed from the database using server-side cursors.
|
||||||
|
|
||||||
.. deprecated:: 4.1
|
|
||||||
|
|
||||||
Using ``iterator()`` on a queryset that prefetches related objects without
|
|
||||||
providing the ``chunk_size`` is deprecated. In Django 5.0, an exception
|
|
||||||
will be raise.
|
|
||||||
|
|
||||||
With server-side cursors
|
With server-side cursors
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
@ -319,3 +319,6 @@ to remove usage of these features.
|
|||||||
``SimpleTestCase.assertFormError()`` and ``assertFormsetError()`` is removed.
|
``SimpleTestCase.assertFormError()`` and ``assertFormsetError()`` is removed.
|
||||||
|
|
||||||
* ``django.contrib.sessions.serializers.PickleSerializer`` is removed.
|
* ``django.contrib.sessions.serializers.PickleSerializer`` is removed.
|
||||||
|
|
||||||
|
* The usage of ``QuerySet.iterator()`` on a queryset that prefetches related
|
||||||
|
objects without providing the ``chunk_size`` argument is no longer allowed.
|
||||||
|
@ -12,8 +12,7 @@ from django.test import (
|
|||||||
skipIfDBFeature,
|
skipIfDBFeature,
|
||||||
skipUnlessDBFeature,
|
skipUnlessDBFeature,
|
||||||
)
|
)
|
||||||
from django.test.utils import CaptureQueriesContext, ignore_warnings
|
from django.test.utils import CaptureQueriesContext
|
||||||
from django.utils.deprecation import RemovedInDjango50Warning
|
|
||||||
|
|
||||||
from .models import (
|
from .models import (
|
||||||
Article,
|
Article,
|
||||||
@ -385,25 +384,12 @@ class PrefetchRelatedTests(TestDataMixin, TestCase):
|
|||||||
[self.author1, self.author1, self.author3, self.author4],
|
[self.author1, self.author1, self.author3, self.author4],
|
||||||
)
|
)
|
||||||
|
|
||||||
@ignore_warnings(category=RemovedInDjango50Warning)
|
def test_m2m_prefetching_iterator_without_chunks_error(self):
|
||||||
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):
|
|
||||||
msg = (
|
msg = (
|
||||||
"Using QuerySet.iterator() after prefetch_related() without "
|
"chunk_size must be provided when using QuerySet.iterator() after "
|
||||||
"specifying chunk_size is deprecated."
|
"prefetch_related()."
|
||||||
)
|
)
|
||||||
with self.assertWarnsMessage(RemovedInDjango50Warning, msg):
|
with self.assertRaisesMessage(ValueError, msg):
|
||||||
Book.objects.prefetch_related("authors").iterator()
|
Book.objects.prefetch_related("authors").iterator()
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user