From 07394506a7d78d3dbfea081669df6a5009053a86 Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Thu, 18 Jun 2026 10:14:44 -0400 Subject: [PATCH 1/3] Added test for updating a model instance with a db_default. --- tests/field_defaults/tests.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/field_defaults/tests.py b/tests/field_defaults/tests.py index c4b978d1693a..9e9606e295ee 100644 --- a/tests/field_defaults/tests.py +++ b/tests/field_defaults/tests.py @@ -98,6 +98,17 @@ def test_both_default(self): obj2 = DBDefaults.objects.create() self.assertEqual(obj2.both, 1) + def test_db_default_blind_overwrite(self): + """ + Perform a blind overwrite: instantiate an object with a known pk + without fetching it, and overwrite some values. The db_default is used. + """ + obj1 = DBDefaults.objects.create(null=1.2) + unfetched_instance = DBDefaults(pk=obj1.pk) + unfetched_instance.save() + obj1.refresh_from_db() + self.assertEqual(obj1.null, 1.1) + def test_pk_db_default(self): obj1 = DBDefaultsPK.objects.create() if not connection.features.can_return_columns_from_insert: From ca5746b8680a5e7e14014d365c0610f825df1dae Mon Sep 17 00:00:00 2001 From: zhengkangyang <1872483761@qq.com> Date: Sun, 7 Jun 2026 01:01:43 +0800 Subject: [PATCH 2/3] Fixed #37143 -- Added missing chunk_size=None check to QuerySet.aiterator(). Co-authored-by: Jacob Walls --- django/db/models/query.py | 26 ++++++++++++++++++++++---- docs/internals/deprecation.txt | 3 +++ docs/releases/6.2.txt | 5 +++++ tests/async/test_async_queryset.py | 24 +++++++++++++++++++++++- 4 files changed, 53 insertions(+), 5 deletions(-) diff --git a/django/db/models/query.py b/django/db/models/query.py index e4b37d1c52bf..3ede5220cc03 100644 --- a/django/db/models/query.py +++ b/django/db/models/query.py @@ -37,7 +37,7 @@ resolve_callables, ) from django.utils import timezone -from django.utils.deprecation import RemovedInDjango70Warning +from django.utils.deprecation import RemovedInDjango70Warning, RemovedInDjango71Warning from django.utils.functional import cached_property from django.utils.warnings import django_file_prefixes @@ -577,18 +577,36 @@ def iterator(self, chunk_size=None): ) return self._iterator(use_chunked_fetch, chunk_size) - async def aiterator(self, chunk_size=2000): + async def aiterator(self, chunk_size=None): """ An asynchronous iterator over the results from applying this QuerySet to the database. """ - if chunk_size <= 0: + if chunk_size is None: + if self._prefetch_related_lookups: + # RemovedInDjango71Warning: Replace the warning with: + # raise ValueError( + # "chunk_size must be provided when using " + # "QuerySet.aiterator() after prefetch_related()." + # ) + warnings.warn( + "Using QuerySet.aiterator() after prefetch_related() without " + "providing a chunk_size is deprecated and will raise a " + "ValueError in Django 7.1.", + category=RemovedInDjango71Warning, + skip_file_prefixes=django_file_prefixes(), + ) + # RemovedInDjango71Warning: When the deprecation ends, remove. + chunk_size = 2000 + elif chunk_size <= 0: raise ValueError("Chunk size must be strictly positive.") use_chunked_fetch = not connections[self.db].settings_dict.get( "DISABLE_SERVER_SIDE_CURSORS" ) iterable = self._iterable_class( - self, chunked_fetch=use_chunked_fetch, chunk_size=chunk_size + self, + chunked_fetch=use_chunked_fetch, + chunk_size=chunk_size or 2000, ) if self._prefetch_related_lookups: results = [] diff --git a/docs/internals/deprecation.txt b/docs/internals/deprecation.txt index 4eda66e54426..2a4e8aca27a1 100644 --- a/docs/internals/deprecation.txt +++ b/docs/internals/deprecation.txt @@ -17,6 +17,9 @@ details on these changes. * The ``safe`` parameter of :class:`~django.http.JsonResponse` will be removed. +* Calling ``QuerySet.aiterator()`` after ``prefetch_related()`` without + providing a ``chunk_size`` will raise :exc:`ValueError`. + .. _deprecation-removed-in-7.0: 7.0 diff --git a/docs/releases/6.2.txt b/docs/releases/6.2.txt index f1bde4805ca3..2c420f83e982 100644 --- a/docs/releases/6.2.txt +++ b/docs/releases/6.2.txt @@ -278,3 +278,8 @@ Miscellaneous * The ``safe`` parameter is deprecated from :class:`~django.http.JsonResponse`. Omitting the argument is equivalent to the prior ``safe=False`` usage. + +* Calling :meth:`.QuerySet.aiterator` after ``prefetch_related()`` without + providing a ``chunk_size`` is deprecated. It currently falls back to a + ``chunk_size`` of 2000, but a ``ValueError`` will be raised in + Django 7.1. diff --git a/tests/async/test_async_queryset.py b/tests/async/test_async_queryset.py index 374b4576f98f..f04127470155 100644 --- a/tests/async/test_async_queryset.py +++ b/tests/async/test_async_queryset.py @@ -7,6 +7,7 @@ from django.db import NotSupportedError, connection from django.db.models import Prefetch, Sum from django.test import TestCase, skipIfDBFeature, skipUnlessDBFeature +from django.utils.deprecation import RemovedInDjango71Warning from .models import RelatedModel, SimpleModel @@ -54,10 +55,31 @@ async def test_aiterator_prefetch_related(self): results = [] async for s in SimpleModel.objects.prefetch_related( Prefetch("relatedmodel_set", to_attr="prefetched_relatedmodel") - ).aiterator(): + ).aiterator(chunk_size=2000): results.append(s.prefetched_relatedmodel) self.assertCountEqual(results, [[self.r1], [self.r2], [self.r3]]) + async def test_aiterator_prefetch_related_chunk_size_none(self): + msg = ( + "Using QuerySet.aiterator() after prefetch_related() without " + "providing a chunk_size is deprecated" + ) + qs = SimpleModel.objects.prefetch_related("relatedmodel_set").aiterator() + + # RemovedInDjango71Warning: When the deprecation ends, replace with: + # with self.assertRaisesMessage( + # ValueError, + # "chunk_size must be provided when using QuerySet.aiterator() " + # "after prefetch_related().", + # ): + # async for _ in qs: + # pass + results = [] + with self.assertWarnsMessage(RemovedInDjango71Warning, msg): + async for s in qs: + results.append(s) + self.assertCountEqual(results, [self.s1, self.s2, self.s3]) + async def test_aiterator_invalid_chunk_size(self): msg = "Chunk size must be strictly positive." for size in [0, -1]: From aa0efc9e221e023c21ca0ff17f1b1300a3d4ebe2 Mon Sep 17 00:00:00 2001 From: Margaret Fero Date: Wed, 10 Jun 2026 19:35:00 -0700 Subject: [PATCH 3/3] Fixed #37146 -- Improved new-user experience of README's Trac link. Trac link in README was throwing a bunch of errors at newcomers. --- AUTHORS | 1 + README.rst | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/AUTHORS b/AUTHORS index 5b06d4ef2fa0..9187d1a6a5d5 100644 --- a/AUTHORS +++ b/AUTHORS @@ -683,6 +683,7 @@ answer newbie questions, and generally made Django that much better: Marc Seguí Coll Marc Tamlyn Marc-Aurèle Brothier + Margaret Fero Marian Andre Marijke Luttekes Marijn Vriens diff --git a/README.rst b/README.rst index b7532e6b5ad3..f6209e36d8c4 100644 --- a/README.rst +++ b/README.rst @@ -24,8 +24,10 @@ here's how we recommend you read the docs: * See ``docs/README`` for instructions on building an HTML version of the docs. Docs are updated rigorously. If you find any problems in the docs, or think -they should be clarified in any way, please take 30 seconds to fill out a -ticket here: https://code.djangoproject.com/newticket +they should be clarified in any way, please take 30 seconds to +`fill out a ticket `_. You can log in +with your GitHub account, or with a DjangoProject account if you have one. Once +you log in, a New Ticket button is available next to View Tickets. To get more help: